diff --git a/config b/config index ca0c64d..e54d7e3 100644 --- a/config +++ b/config @@ -5,7 +5,7 @@ TARO_LIB=${PWD} # where attachments are saved to TARO_DOWNLOADS=${HOME}/tmp -# name of your uxnemu executable; it must be in PATH; i copy mine to "taro" so it gets the _NET_WM_CLASS=taro +# name of your uxnemu executable; it must be in PATH; i copy mine to "taro" so it gets the _NET_WM_CLASS=taro - there may be a better way to do this in the future UXN_EMU=taro # any custom env you want to set for reader/compose wins diff --git a/taro-ctl.cr b/taro-ctl.cr index 7ff7327..34f7886 100644 --- a/taro-ctl.cr +++ b/taro-ctl.cr @@ -4,22 +4,38 @@ require "socket" require "./config" -MSG_SIZES = { - 0_u8 => 4096_u16, - 2_u8 => 32768_u16, -} - -def u8arr_tou16(s : Slice(UInt8)) : UInt16 - if s.size < 2 - return 0_u16 - else - low : UInt16 = UInt16.new(s[0])*256 - high : UInt16 = UInt16.new(s[1]) - return low + high - end -end +at_exit { GC.collect } module Taro + + enum MsgType : UInt8 + MBOX_LIST + GET_MBOX + MAIL_LIST + MARK_ALL_READ + SEARCH_MAIL = 5 + REFILE_MAIL = 7 + TRASH_MAIL = 9 + READ_MAIL = 11 + COMPOSE_MAIL = 13 + UPDATE_UI = 15 + end + + MSG_SIZES = { + MsgType::MBOX_LIST => 4096_u16, + MsgType::MAIL_LIST => 32768_u16, + } + + def u8arr_tou16(s : Slice(UInt8)) : UInt16 + if s.size < 2 + return 0_u16 + else + low : UInt16 = UInt16.new(s[0])*256 + high : UInt16 = UInt16.new(s[1]) + return low + high + end + end + enum WinType LIST READER @@ -27,7 +43,7 @@ module Taro end class Mesg - @type : UInt8 + @type : MsgType @data : Slice(UInt8) def type @@ -43,6 +59,8 @@ module Taro end class ChildWindow + include Taro + @@msg : Channel(Mesg) = Channel(Mesg).new def self.msg @@ -86,12 +104,12 @@ module Taro when WinType::READER then spawn do Process.run(command: READER_PROG + " " + arg, shell: true) - @@msg.send(Mesg.new(15_u8, Slice(UInt8).new(0))) + @@msg.send(Mesg.new(MsgType::UPDATE_UI, Slice(UInt8).new(0))) end when WinType::COMPOSE then spawn do Process.run(command: COMPOSE_PROG, shell: true) - @@msg.send(Mesg.new(15_u8, Slice(UInt8).new(0))) + @@msg.send(Mesg.new(MsgType::UPDATE_UI, Slice(UInt8).new(0))) end end @@ -101,11 +119,11 @@ module Taro @lifetime end - def write_msg(msgtype : UInt8, data : Slice) + def write_msg(msgtype : MsgType, data : Slice) puts "original message size: " + data.size.to_s msgsz = UInt16.new(data.size > MSG_SIZES[msgtype] ? MSG_SIZES[msgtype] : data.size) puts "truncated message size: " + msgsz.to_s - msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian) + msgtype.value.to_io(@stdin_w, IO::ByteFormat::BigEndian) msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian) if msgsz == MSG_SIZES[msgtype] @@ -117,7 +135,7 @@ module Taro end def read_msg - msgType : UInt8 = 0 + msgType : MsgType = MsgType::MBOX_LIST data : Slice(UInt8) = Slice(UInt8).new(0) loop do if @stdout_r.closed? @@ -127,7 +145,7 @@ module Taro break end if !@decoding - msgType = @stdout_r.read_byte || 0_u8 + msgType = MsgType.new(@stdout_r.read_byte || 0_u8) @decoding = true @sizing = true elsif @sizing @@ -228,92 +246,79 @@ module Taro class TaroCtl + include Taro + @mblaze : MblazeProxy @lsWin : ChildWindow - @readWins : Array(ChildWindow) - @composeWins : Array(ChildWindow) + @socket : UNIXServer def initialize @lsWin = ChildWindow.new - @readWins = Array(ChildWindow).new - @composeWins = Array(ChildWindow).new - @mblaze = MblazeProxy.new + + File.delete?("#{TARO_LIB}/taro.sock") + @socket = UNIXServer.new("#{TARO_LIB}/taro.sock") + list = @mblaze.list_mail mboxes = @mblaze.list_mboxes - @lsWin.write_msg(0_u8, mboxes.to_slice) - @lsWin.write_msg(2_u8, list.to_slice) + @lsWin.write_msg(MsgType::MBOX_LIST, mboxes.to_slice) + @lsWin.write_msg(MsgType::MAIL_LIST, list.to_slice) end - def mblaze - @mblaze + def run + spawn do + while client = @socket.accept? + spawn do + b = Slice(UInt8).new(1) + client.read(b) + ChildWindow.msg.send(Mesg.new(MsgType::UPDATE_UI, Slice(UInt8).new(0))) + end + end + end + + loop do + select + when @lsWin.lifetime.receive? + @socket.close + exit + when m = ChildWindow.msg.receive + case m.type + when MsgType::GET_MBOX then + @mblaze.set_mbox(String.new(m.data)) + @lsWin.write_msg(MsgType::MAIL_LIST, @mblaze.list_mail.to_slice) + when MsgType::MARK_ALL_READ then + @mblaze.mark_all_read + @lsWin.write_msg(MsgType::MAIL_LIST, @mblaze.list_mail.to_slice) + when MsgType::SEARCH_MAIL then + search_results = @mblaze.search_mail(String.new(m.data), false, false) + @lsWin.write_msg(MsgType::MAIL_LIST, search_results.to_slice) + when MsgType::REFILE_MAIL then + range_start = u8arr_tou16(m.data[0..1]) + range_end = u8arr_tou16(m.data[2..3]) + dest_mbox = String.new(m.data[4..]) + @mblaze.refile_mail(range_start, range_end, dest_mbox) + @lsWin.write_msg(MsgType::MAIL_LIST, @mblaze.list_mail.to_slice) + when MsgType::TRASH_MAIL then + range_start = u8arr_tou16(m.data[0..1]) + range_end = u8arr_tou16(m.data[2..3]) + @mblaze.trash_mail(range_start, range_end) + @lsWin.write_msg(MsgType::MAIL_LIST, @mblaze.list_mail.to_slice) + when MsgType::READ_MAIL then + mmsg = u8arr_tou16(m.data[0..1]) + ChildWindow.new(WinType::READER, mmsg.to_s) + when MsgType::COMPOSE_MAIL then + ChildWindow.new(WinType::COMPOSE) + when MsgType::UPDATE_UI then + @lsWin.write_msg(MsgType::MAIL_LIST, @mblaze.list_mail.to_slice) + end + end + end end - - def mainWindow - @lsWin - end - - def readWins - @readWins - end - - def composeWins - @composeWins - end + end end taro = Taro::TaroCtl.new +taro.run -File.delete?("#{TARO_LIB}/taro.sock") -srv = UNIXServer.new("#{TARO_LIB}/taro.sock") - -spawn do - while client = srv.accept? - spawn do - b = Slice(UInt8).new(1) - client.read(b) - Taro::ChildWindow.msg.send(Taro::Mesg.new(15_u8, Slice(UInt8).new(0))) - end - end -end - - -loop do - select - when taro.mainWindow.lifetime.receive? - srv.close - exit - when m = Taro::ChildWindow.msg.receive - case m.type - when 1 then - taro.mblaze.set_mbox(String.new(m.data)) - taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) - when 3 then - taro.mblaze.mark_all_read - taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) - when 5 then - search_results = taro.mblaze.search_mail(String.new(m.data), false, false) - taro.mainWindow.write_msg(2_u8, search_results.to_slice) - when 7 then - range_start = u8arr_tou16(m.data[0..1]) - range_end = u8arr_tou16(m.data[2..3]) - dest_mbox = String.new(m.data[4..]) - taro.mblaze.refile_mail(range_start, range_end, dest_mbox) - taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) - when 9 then - range_start = u8arr_tou16(m.data[0..1]) - range_end = u8arr_tou16(m.data[2..3]) - taro.mblaze.trash_mail(range_start, range_end) - taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) - when 11 then - mmsg = u8arr_tou16(m.data[0..1]) - Taro::ChildWindow.new(Taro::WinType::READER, mmsg.to_s) - when 13 then - Taro::ChildWindow.new(Taro::WinType::COMPOSE) - when 15 then - taro.mainWindow.write_msg(2_u8, taro.mblaze.list_mail.to_slice) - end - end -end diff --git a/taro-ls.tal b/taro-ls.tal index fb364a0..f607334 100644 --- a/taro-ls.tal +++ b/taro-ls.tal @@ -11,6 +11,7 @@ %TRASH_MAIL { #09 } %READ_MAIL { #0b } %COMPOSE_MAIL { #0d } +%UPDATE_UI { #0f } ( UI constants ) @@ -72,6 +73,8 @@ |0100 ( -> ) + ;metadata #06 DEO2 + ( theme ) #028d .System/r DEO2 #0a8d .System/g DEO2 @@ -109,11 +112,12 @@ ;enter_refile_mode .btn_fns/refile STZ2 ;send_trash .btn_fns/trash STZ2 - + ;on_screen .Screen/vector DEO2 ;on_mouse .Mouse/vector DEO2 ;on_stdin .Console/vector DEO2 ;on_key .Controller/vector DEO2 + BRK ( -== message in ==- ) @@ -280,7 +284,6 @@ JMP2r ( message size is 0, no payload ) JMP2r - @send_str ( str* -- ) @@ -302,6 +305,7 @@ JMP2r ( -== input ==- ) @on_key ( -> ) + .textbox/mode LDZ #00 EQU ,&no_text_entry JCN handle_textbox BRK @@ -1189,7 +1193,7 @@ JMP2r ;theme_file .File0/name DEO2 #0006 .File0/length DEO2 ;theme_data .File0/read DEO2 - .File0/success DEI2 DUP2 debug_u16 #0006 NEQ2 ,&no_theme_file JCN + .File0/success DEI2 #0006 NEQ2 ,&no_theme_file JCN ;theme_data LDA2 .System/r DEO2 ;theme_data #0002 ADD2 LDA2 .System/g DEO2 ;theme_data #0004 ADD2 LDA2 .System/b DEO2 @@ -1250,6 +1254,11 @@ JMP2r @bone [ e040 4040 4040 40e0 ] +@metadata 00 "taro 0a + "v0.2.0 0a + "GUI 20 "for 20 "mblaze 0a + "Derek 20 "Stevens 20 " 0a 00 + @selected_mbox "INBOX 00 $f9 ( default mailbox is INBOX, total space #06 + #f9 = #ff bytes ) @font $300 @theme_data $6