mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	feat: implement message managing functions
This commit is contained in:
		
							parent
							
								
									34a5b2aedd
								
							
						
					
					
						commit
						466ca06f79
					
				| @ -36,22 +36,54 @@ function hilbish.messages.send(message) | |||||||
| 	expect(message, 'title') | 	expect(message, 'title') | ||||||
| 	counter = counter + 1 | 	counter = counter + 1 | ||||||
| 	message.index = counter | 	message.index = counter | ||||||
|  | 	message.read = false | ||||||
| 
 | 
 | ||||||
| 	M._messages[message.index] = message | 	M._messages[message.index] = message | ||||||
| 	bait.throw('hilbish.notification', message) | 	bait.throw('hilbish.notification', message) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | function hilbish.messages.read(idx) | ||||||
|  | 	local msg = M._messages[idx] | ||||||
|  | 	if msg then | ||||||
|  | 		M._messages[idx].read = true | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function hilbish.messages.readAll(idx) | ||||||
|  | 	for _, msg in ipairs(hilbish.messages.all()) do | ||||||
|  | 		hilbish.messages.read(msg.index) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function hilbish.messages.delete(idx) | ||||||
|  | 	local msg = M._messages[idx] | ||||||
|  | 	if not msg then | ||||||
|  | 		error(string.format('invalid message index %d', idx or -1)) | ||||||
|  | 	end | ||||||
|  | 
 | ||||||
|  | 	M._messages[idx] = nil | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function hilbish.messages.clear() | ||||||
|  | 	for _, msg in ipairs(hilbish.messages.all()) do | ||||||
|  | 		hilbish.messages.delete(msg.index) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  | 
 | ||||||
| function hilbish.messages.all() | function hilbish.messages.all() | ||||||
| 	return M._messages | 	return M._messages | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| commander.register('messages', function(_, sinks) | commander.register('messages', function(_, sinks) | ||||||
| 	for _, msg in ipairs(hilbish.messages.all()) do | 	for idx = counter, 1, -1  do | ||||||
|  | 		local msg = M._messages[idx] | ||||||
|  | 		if msg then | ||||||
| 			local heading = lunacolors.format(string.format('Message {cyan}#%d{reset}: %s', msg.index, msg.title)) | 			local heading = lunacolors.format(string.format('Message {cyan}#%d{reset}: %s', msg.index, msg.title)) | ||||||
| 			sinks.out:writeln(heading) | 			sinks.out:writeln(heading) | ||||||
| 			sinks.out:writeln(string.rep('=', string.len(heading))) | 			sinks.out:writeln(string.rep('=', string.len(heading))) | ||||||
| 			sinks.out:writeln(msg.text) | 			sinks.out:writeln(msg.text) | ||||||
| 		end | 		end | ||||||
|  | 	end | ||||||
| end) | end) | ||||||
| 
 | 
 | ||||||
| return M | return M | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user