mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	feat: add basic notification/message interface
This commit is contained in:
		
							parent
							
								
									6be65c04a6
								
							
						
					
					
						commit
						c1647646b2
					
				| @ -1,4 +1,5 @@ | ||||
| -- Default Hilbish config | ||||
| local hilbish = require 'hilbish' | ||||
| local lunacolors = require 'lunacolors' | ||||
| local bait = require 'bait' | ||||
| local ansikit = require 'ansikit' | ||||
| @ -22,3 +23,17 @@ bait.catch('hilbish.vimMode', function(mode) | ||||
| 		ansikit.cursorStyle(ansikit.lineCursor) | ||||
| 	end | ||||
| end) | ||||
| 
 | ||||
| --[[ | ||||
| hilbish.timeout(function() | ||||
| 	hilbish.messages.send {title = 'greetings!', text = 'hello world :D'} | ||||
| end, 2000) | ||||
| ]]-- | ||||
| 
 | ||||
| bait.catch('hilbish.notification', function() | ||||
| 	hilbish.prompt(lunacolors.blue('• 1 new notification'), 'right') | ||||
| 
 | ||||
| 	hilbish.timeout(function() | ||||
| 		hilbish.prompt('', 'right') | ||||
| 	end, 3000) | ||||
| end) | ||||
|  | ||||
							
								
								
									
										56
									
								
								nature/hummingbird.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								nature/hummingbird.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,56 @@ | ||||
| local bait = require 'bait' | ||||
| local commander = require 'commander' | ||||
| local lunacolors = require 'lunacolors' | ||||
| 
 | ||||
| local M = {} | ||||
| local counter = 0 | ||||
| M._messages = {} | ||||
| M.icons = { | ||||
| 	INFO = '', | ||||
| 	SUCCESS = '', | ||||
| 	WARN = '', | ||||
| 	ERROR = '' | ||||
| } | ||||
| 
 | ||||
| hilbish.messages = {} | ||||
| 
 | ||||
| --- Represents a Hilbish message. | ||||
| --- @class hilbish.message | ||||
| --- @field icon string Unicode (preferably standard emoji) icon for the message notification. | ||||
| --- @field title string Title of the message (like an email subject). | ||||
| --- @field text string Contents of the message. | ||||
| --- @field channel string Short identifier of the message. `hilbish` and `hilbish.*` is preserved for internal Hilbish messages. | ||||
| --- @field summary string A short summary of the message. | ||||
| --- @field read boolean Whether the full message has been read or not. | ||||
| 
 | ||||
| function expect(tbl, field) | ||||
| 	if not tbl[field] or tbl[field] == '' then | ||||
| 		error(string.format('expected field %s in message')) | ||||
| 	end | ||||
| end | ||||
| 
 | ||||
| --- Sends a message. | ||||
| --- @param message hilbish.message | ||||
| function hilbish.messages.send(message) | ||||
| 	expect(message, 'text') | ||||
| 	expect(message, 'title') | ||||
| 	message.index = counter + 1 | ||||
| 
 | ||||
| 	M._messages[message.index] = message | ||||
| 	bait.throw('hilbish.notification', message) | ||||
| end | ||||
| 
 | ||||
| function hilbish.messages.all() | ||||
| 	return M._messages | ||||
| end | ||||
| 
 | ||||
| commander.register('messages', function(_, sinks) | ||||
| 	for _, msg in ipairs(hilbish.messages.all()) do | ||||
| 		local heading = lunacolors.format(string.format('Message {cyan}#%d{reset}: %s', msg.index, msg.title)) | ||||
| 		sinks.out:writeln(heading) | ||||
| 		sinks.out:writeln(string.rep('=', string.len(heading))) | ||||
| 		sinks.out:writeln(msg.text) | ||||
| 	end | ||||
| end) | ||||
| 
 | ||||
| return M | ||||
| @ -11,6 +11,7 @@ require 'nature.completions' | ||||
| require 'nature.opts' | ||||
| require 'nature.vim' | ||||
| require 'nature.runner' | ||||
| require 'nature.hummingbird' | ||||
| 
 | ||||
| local shlvl = tonumber(os.getenv 'SHLVL') | ||||
| if shlvl ~= nil then | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user