all repos — taro @ f3a781e42b661778a4f9f67a9e323d8098d53764

mblaze frontend in uxn + crystal

taro-ctl: use enum for msg types and put everything in the namespace; taro-ls: add manifest and remove debug call
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmQj0roACgkQO3+8IhRO
Y5i32Q/+M/kKz7X/Ii5tzsw9JFDSQ6GDiuLJW86E64AqHfvyoURAoo/l/HRQqBpn
jAiIQsAZ4e+X0fnULrn4rLjhGLg0yv8mos3iaJFjeWw4ACaGfcxf70k+MnYRQx3G
2xosUe8TVlCrqXlN9K+5ikIzrzZMyVTGbx4FWT7D8KVkw5gx/RtNgV8cIDAhvCQE
0I3tRGLbrxz62MvPd34XeGgfqfAgO0xB7pONVi6/zi+9hObhU8TI70Bw64QUhVdy
21pYfS5W0nxBd9SnYgHjS43qWKZR5diFQdM8T/dD0/Eq9dbnpmQKo76t5ZdPBBXf
LCK3PLnmmtpsi62Oz3HpvEYAuckgbzOt0WTBOevHHgiyb6NI77XN3lCAfx7qRLBU
VS1JISi8W21D2tNcm64QTvtoTRGtztcI9mzmdx4+fM6vHKipjln/4lVJDGR97qC9
cYw1oB2Im+ojfB6waFMVn69aUmjISV+/96fpJFLzUAF56KzArt+CbDuicWIOHsKP
/3JQGCLAbdbsla0N9x5Wwiotip09APDE3KmSd1LZHmD6BGD4ecMdfEh7c3Clvv8i
KQVt6q498qbdsWN8HpIwjhUINTXhISv8Ner2Hbh3eslaS/B+gbuvOA4AOrLPTZdJ
K0/s5Aj5lRjUsJRS5p7Am48ymVIrSA5u1X1W9bGHUeLWxUyXXrk=
=kap5
-----END PGP SIGNATURE-----
commit

f3a781e42b661778a4f9f67a9e323d8098d53764

parent

42e78087a83e05588c5720e3d36d75a5459869aa

3 files changed, 110 insertions(+), 96 deletions(-)

jump to
M configconfig

@@ -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
M taro-ctl.crtaro-ctl.cr

@@ -4,22 +4,38 @@ require "socket"

require "./config" -MSG_SIZES = { - 0_u8 => 4096_u16, - 2_u8 => 32768_u16, -} +at_exit { GC.collect } -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 +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 -end -module Taro + 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 @@ COMPOSE

end class Mesg - @type : UInt8 + @type : MsgType @data : Slice(UInt8) def type

@@ -43,6 +59,8 @@ end

end class ChildWindow + include Taro + @@msg : Channel(Mesg) = Channel(Mesg).new def self.msg

@@ -86,12 +104,12 @@ end

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 @@ def lifetime

@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 @@ end

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 @@ @szshort = 0

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 @@ end

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") - @mblaze = MblazeProxy.new 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 - end - - def mainWindow - @lsWin + 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 readWins - @readWins - end - - def composeWins - @composeWins - end + end end taro = Taro::TaroCtl.new - -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 - +taro.run -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
M taro-ls.taltaro-ls.tal

@@ -11,6 +11,7 @@ %REFILE_MAIL { #07 }

%TRASH_MAIL { #09 } %READ_MAIL { #0b } %COMPOSE_MAIL { #0d } +%UPDATE_UI { #0f } ( UI constants )

@@ -72,6 +73,8 @@ ( program )

|0100 ( -> ) + ;metadata #06 DEO2 + ( theme ) #028d .System/r DEO2 #0a8d .System/g DEO2

@@ -109,11 +112,12 @@ ;enter_search_mode .btn_fns/search STZ2

;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 @@ #00 .Console/write DEOk DEO

( message size is 0, no payload ) JMP2r - @send_str ( str* -- )

@@ -302,6 +305,7 @@

( -== input ==- ) @on_key ( -> ) + .textbox/mode LDZ #00 EQU ,&no_text_entry JCN handle_textbox BRK

@@ -1189,7 +1193,7 @@

;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

@@ -1249,6 +1253,11 @@ 0408 191e 1d00 0000 4080 00a8 5000 0000

] @bone [ e040 4040 4040 40e0 ] + +@metadata 00 "taro 0a + "v0.2.0 0a + "GUI 20 "for 20 "mblaze 0a + "Derek 20 "Stevens 20 "<nilix@nilfm.cc> 0a 00 @selected_mbox "INBOX 00 $f9 ( default mailbox is INBOX, total space #06 + #f9 = #ff bytes ) @font $300