From d2a3e71fd656d630a289b5182b56a5085a79a751 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Thu, 30 Mar 2023 21:13:35 -0600 Subject: [PATCH] taro-ctl: eliminate puts calls and don't convert from IO::Memory in MblazeProxy; taro-ls: various optimizations, reset scrollbar when changing mbox --- taro-ctl.cr | 14 +++--- taro-ls.tal | 126 ++++++++++++++++++++++++++-------------------------- 2 files changed, 69 insertions(+), 71 deletions(-) diff --git a/taro-ctl.cr b/taro-ctl.cr index 2f93db7..7d24e31 100644 --- a/taro-ctl.cr +++ b/taro-ctl.cr @@ -117,9 +117,7 @@ module Taro end 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.value.to_io(@stdin_w, IO::ByteFormat::BigEndian) msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian) @@ -163,7 +161,6 @@ module Taro break end end - puts data return Mesg.new(msgType, data) end @@ -181,14 +178,13 @@ module Taro @@search_regex end - private def run_cmd(cmdtxt : String) : String - puts cmdtxt + private def run_cmd(cmdtxt : String) : IO::Memory io = IO::Memory.new Process.run(cmdtxt, shell: true, output: io) - return io.to_s + return io end - def list_mail : String + def list_mail : IO::Memory if @@search_regex != "" return search_mail(@@search_regex, false, false) end @@ -201,7 +197,7 @@ module Taro return run_cmd(cmd) end - def list_mboxes : String + def list_mboxes : IO::Memory cmd = "echo 'INBOX' ; for x in $(mdirs -a #{MBOX_ROOT} | sort | grep -v INBOX); do echo ${x##{MBOX_ROOT}/}; done" return run_cmd(cmd) @@ -233,7 +229,7 @@ module Taro run_cmd(cmd) end - def search_mail(query : String, body : Bool, case_sensitive : Bool) : String + def search_mail(query : String, body : Bool, case_sensitive : Bool) : IO::Memory query = query.gsub("'", "\'") @@search_regex = query cmd = "mlist #{MBOX_ROOT}/#{@@mailbox} | magrep #{case_sensitive ? "" : "-i"} #{body ? "/" : "*"}:'#{query}' | msort -dr | uniq | mseq -S | mscan" diff --git a/taro-ls.tal b/taro-ls.tal index a232131..3954f99 100644 --- a/taro-ls.tal +++ b/taro-ls.tal @@ -58,7 +58,7 @@ @refresh [ &mboxes $1 &list $1 &fg $1 &btns $1 &textbox $1 &etc $1 ] @resizing [ $1 &x $2 &y $2 &dx $2 &dy $2 ] -@decoding [ $1 &msg_type $1 &counting $1 &count $2 &processed $2 ] +@decoding [ $1 &msg_type $1 &counting $1 &count $1 &count2 $1 &processed $2 ] @textbox [ &mode $1 &len $1 &cursor $1 &msg $2 &searching $1 ] @mboxes [ &bytes $2 &data $2 &len $2 &offset $2 &elem_offset $1 &top $2 &height $1 &select_index $2 &select_len $2 @@ -75,7 +75,7 @@ ;metadata #06 DEO2 - ( theme ) + ( default theme ) #028d .System/r DEO2 #0a8d .System/g DEO2 #098d .System/b DEO2 @@ -164,7 +164,7 @@ BRK BRK &count_2 - .Console/read DEI .decoding/count INC STZ + .Console/read DEI .decoding/count2 STZ #00 .decoding/counting STZ ( handle empty payload ) @@ -207,7 +207,7 @@ JMP2r ( -== message out ==- ) -@send_get_mbox ( -> ) +@send_get_mbox ( -- ) #01 .Console/write DEO ;selected_mbox strlen SWP .Console/write DEO .Console/write DEO @@ -216,13 +216,15 @@ JMP2r #0000 .list/select_index STZ2 #0001 .list/select_len STZ2 #0000 .list/top STZ2 + + .list update_sb_pos #00 .textbox/searching STZ #01 .refresh/etc STZ JMP2r -@send_mark_all_read ( -> ) +@send_mark_all_read ( -- ) MARK_ALL_READ .Console/write DEO #00 .Console/write DEOk DEO @@ -230,7 +232,7 @@ JMP2r JMP2r -@send_search ( -> ) +@send_search ( -- ) SEARCH_MAIL .Console/write DEO ;textbox_text strlen SWP .Console/write DEO .Console/write DEO @@ -240,7 +242,7 @@ JMP2r JMP2r -@send_refile ( -> ) +@send_refile ( -- ) REFILE_MAIL .Console/write DEO #0004 ;textbox_text strlen ADD2 SWP .Console/write DEO .Console/write DEO @@ -251,7 +253,7 @@ JMP2r JMP2r -@send_trash ( -> ) +@send_trash ( -- ) TRASH_MAIL .Console/write DEO #0004 SWP .Console/write DEO .Console/write DEO @@ -261,7 +263,7 @@ JMP2r JMP2r -@send_reader ( -> ) +@send_reader ( -- ) ( reset the mouse state since if a window opens over the uxn window mid-click and steals focus, the click never releases until we click the button again ) @@ -273,7 +275,7 @@ JMP2r JMP2r -@send_compose ( -> ) +@send_compose ( -- ) ( reset the mouse state since if a window opens over the uxn window mid-click and steals focus, the click never releases until we click the button again ) @@ -449,6 +451,7 @@ JMP2r &no_scroll_up &end + STHrk update_sb_pos ( onchange ) STHr ROT ROT JSR2 @@ -457,7 +460,7 @@ JMP2r JMP2r -@handle_textbox ( -> ) +@handle_textbox ( -- ) .Controller/key DEI DUP #00 EQU ,&no_key JCN DUP check_enter_or_esc #01 EQU ,&no_btn JCN @@ -497,21 +500,21 @@ JMP2r .textbox/cursor LDZ .textbox/len LDZ NEQ ,&its_complicated JCN .textbox/cursor LDZ #01 SUB .textbox/cursor STZ .textbox/len LDZ #01 SUB .textbox/len STZ - #00 ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + #00 ;textbox_text #00 .textbox/cursor LDZ ADD2 STA JMP2r &its_complicated ( otherwise loop through characters from cursor to len, and copy them to their location - 1 ) - .textbox/len LDZ #01 ADD .textbox/cursor LDZ &loop EQUk ,&end JCN - DUP #00 SWP ;textbox_text ADD2 LDA STH + .textbox/len LDZ INC .textbox/cursor LDZ &loop EQUk ,&end JCN + #00 OVR ;textbox_text ADD2 LDA STH DUP #01 SUB STHr SWP #00 SWP ;textbox_text ADD2 STA INC ,&loop JMP &end POP2 ( and then decrement counters and set the null byte ) .textbox/cursor LDZ #01 SUB .textbox/cursor STZ .textbox/len LDZ #01 SUB .textbox/len STZ - #00 ;textbox_text .textbox/len LDZ #00 SWP ADD2 STA + #00 ;textbox_text #00 .textbox/len LDZ ADD2 STA JMP2r @@ -521,9 +524,9 @@ JMP2r ( if cursor = len, then add the charater, increment both counters, and add a null byte ) .textbox/cursor LDZ .textbox/len LDZ NEQ ,&its_complicated JCN STHr - ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + ;textbox_text #00 .textbox/cursor LDZ ADD2 STA .textbox/len LDZk INC SWP STZ - #00 ;textbox_text .textbox/len LDZ #00 SWP ADD2 STA + #00 ;textbox_text #00 .textbox/len LDZ ADD2 STA .textbox/cursor LDZk INC SWP STZ JMP2r @@ -531,13 +534,13 @@ JMP2r ( otherwise loop through characters from len to cursor, and copy them to their location + 1 ) .textbox/cursor LDZ #01 SUB .textbox/len LDZ &loop EQUk ,&end JCN - DUP #00 SWP ;textbox_text ADD2 LDA STH + #00 OVR ;textbox_text ADD2 LDA STH DUP INC STHr SWP #00 SWP ;textbox_text ADD2 STA #01 SUB ,&loop JMP &end POP2 STHr ( and put the character at the cursor locaton, then increment the counts ) - ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + ;textbox_text #00 .textbox/cursor LDZ ADD2 STA .textbox/len LDZk INC SWP STZ .textbox/cursor LDZk INC SWP STZ JMP2r @@ -600,11 +603,9 @@ JMP2r BRK -@mouse_event_buttons ( numBtns -- ) +@mouse_event_buttons ( numbtns -- ) - STH - - STHkr #00 &while EQUk ,&end JCN + STHk #00 &while EQUk ,&end JCN DUP .btn_colors ADD DUP LDZ #01 NEQ ,&continue JCN #01 .refresh/btns STZ @@ -615,7 +616,7 @@ BRK ,&while JMP &end POP2 .Mouse/x DEI2 #0008 LTH2 ,&done JCN - .Mouse/x DEI2 #0008 SUB2 [ STHkr #00 SWP #40 SFT2 #0001 SUB2 ] GTH2 ,&done JCN + .Mouse/x DEI2 #0008 SUB2 [ #00 STHkr #40 SFT2 #0001 SUB2 ] GTH2 ,&done JCN .Mouse/y DEI2 .Screen/height DEI2 #0030 SUB2 LTH2 ,&done JCN .Mouse/y DEI2 .Screen/height DEI2 #0020 SUB2 GTH2 ,&done JCN @@ -666,7 +667,7 @@ JMP2r JMP2r -@mouse_event_list ( rightclickhanlder* clickhandler* list refresh ypos* multiselect -- ) +@mouse_event_list ( rightclickhanlder* clickhandler* list refresh ypos* multiselect_mask -- ) ,&multi STR ,&y STR2 @@ -721,7 +722,7 @@ JMP2r JMP2r -@mouse_select_on_click ( multi ypos list -- ) +@mouse_select_on_click ( multi? ypos* list -- ) STH ,&y STR2 @@ -751,7 +752,7 @@ JMP2r ( clear the previous selection with null bytes ) #ff #00 &clear_mbox EQUk ,&ready JCN - DUP #00 SWP ;selected_mbox ADD2 #00 ROT ROT STA + #00 OVR ;selected_mbox ADD2 #00 ROT ROT STA INC ,&clear_mbox JMP &ready POP2 ( get position of the current selection ) @@ -778,14 +779,14 @@ JMP2r JMP2r -@enter_search_mode ( -> ) +@enter_search_mode ( -- ) ENTRY_SEARCH reset_textbox ;search_lbl .textbox/msg STZ2 JMP2r -@enter_refile_mode ( -> ) +@enter_refile_mode ( -- ) ENTRY_REFILE reset_textbox ;refile_lbl .textbox/msg STZ2 @@ -816,8 +817,7 @@ JMP2r @try_scroll_up_mouse ( list -- ) - STH - STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_up JCN + STHk LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_up JCN STHkr LB_TOP LDZ2 #0000 EQU2 ,&no_scroll_up JCN STHkr LB_TOP LDZ2 #0001 SUB2 STHkr LB_TOP STZ2 STHkr update_sb_pos @@ -828,8 +828,7 @@ JMP2r @try_scroll_down_mouse ( list -- ) - STH - STHkr LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_down JCN + STHk LB_LEN LDZ2 #00 STHkr LB_HEIGHT LDZ LTH2 ,&no_scroll_down JCN STHkr LB_TOP LDZ2 #00 STHkr LB_HEIGHT LDZ ADD2 STHkr LB_LEN LDZ2 EQU2 ,&no_scroll_down JCN STHkr LB_TOP LDZ2k INC2 ROT STZ2 STHkr update_sb_pos @@ -888,7 +887,7 @@ JMP2r BRK -@draw_search_indicator ( -> ) +@draw_search_indicator ( -- ) .textbox/searching LDZ #00 EQU ,¬hing JCN ;search_indicator #0000 .Screen/height DEI2 #0008 SUB2 #01 draw_str @@ -900,16 +899,16 @@ BRK #01 .Screen/sprite DEO JMP2r -@draw_bone ( -> ) +@draw_bone ( -- ) - #0008 .textbox/cursor LDZ #00 SWP #30 SFT2 ADD2 .Screen/x DEO2 + #0008 #00 .textbox/cursor LDZ #30 SFT2 ADD2 .Screen/x DEO2 .Screen/height DEI2 #0018 SUB2 .Screen/y DEO2 ;bone .Screen/addr DEO2 #05 .Screen/sprite DEO JMP2r -@clear_textbox ( -> ) +@clear_textbox ( -- ) ;blank .Screen/addr DEO2 .Screen/width DEI2 #0008 &while EQU2k ,&end JCN @@ -922,7 +921,7 @@ JMP2r JMP2r -@clear_fg ( -> ) +@clear_fg ( -- ) ;blank .Screen/addr DEO2 .Screen/width DEI2 #0000 &whilex EQU2k ,&endx JCN @@ -957,7 +956,7 @@ JMP2r &top $2 &height $2 -@draw_resize_handle ( -> ) +@draw_resize_handle ( -- ) .Screen/width DEI2 #0008 SUB2 .Screen/x DEO2 .Screen/height DEI2 #0008 SUB2 .Screen/y DEO2 @@ -976,9 +975,9 @@ JMP2r @shouldnt_draw_word ( list -- bit ) - DUP LB_OFFSET LDZ2 DUP2 + DUP LB_OFFSET LDZ2 ( above top of view ) - STH2 ROT STHk LB_TOP LDZ2 LTH2 ,&clear_rtn JCN + STH2k ROT STHk LB_TOP LDZ2 LTH2 ,&clear_rtn JCN ( below bottom of view ) STHr DUP LB_TOP LDZ2 ROT LB_HEIGHT LDZ #00 SWP ADD2 #0001 SUB2 STH2r SWP2 GTH2 ,&no_draw JCN @@ -1003,7 +1002,7 @@ JMP2r JMP2r -@get_entry_color ( list -- colorByte ) +@get_entry_color ( list -- colorbyte ) STHk LB_OFFSET LDZ2 STHkr LB_SELECT_IDX LDZ2 @@ -1035,7 +1034,7 @@ JMP2r JMP2r -@draw_listbox ( .list ypos* -- ) +@draw_listbox ( list ypos* -- ) #0000 .Screen/x DEO2 ( ypos ) .Screen/y DEO2 @@ -1068,7 +1067,7 @@ JMP2r JMP2r -@draw_cursor ( -> ) +@draw_cursor ( -- ) .Mouse/x DEI2 .Screen/x DEO2 .Mouse/y DEI2 .Screen/y DEO2 @@ -1077,7 +1076,7 @@ JMP2r JMP2r -@draw_scrollbar ( list ypos -- ) +@draw_scrollbar ( list ypos* -- ) ,&y STR2 STH @@ -1125,7 +1124,7 @@ JMP2r JMP2r -@draw_str ( addr x y color -- ) +@draw_str ( addr* x* y* color -- ) STH ( save color ) .Screen/y DEO2 ( set y ) @@ -1170,7 +1169,9 @@ JMP2r JMP2r @debug_u8 ( byte -- ) + #00 SWP debug_u16 + JMP2r @debug_u16 ( short* -- ) @@ -1192,14 +1193,15 @@ JMP2r @load_theme ( -- ) - ;theme_file .File0/name DEO2 - #0006 .File0/length DEO2 - ;theme_data .File0/read DEO2 - .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 + ;theme_file .File0/name DEO2 + #0006 .File0/length DEO2 + ;theme_data .File0/read DEO2 + .File0/success DEI2 #0006 NEQ2 ,&no_theme_file JCN + ;theme_data/r LDA2 .System/r DEO2 + ;theme_data/g LDA2 .System/g DEO2 + ;theme_data/b LDA2 .System/b DEO2 &no_theme_file + JMP2r @load_font ( -- ) @@ -1220,9 +1222,10 @@ JMP2r @refile_lbl "REFILING: 20 "type 20 "destination 20 "and 20 "press 20 "{enter}; 20 "{esc} 20 "to 20 "go 20 "back 00 @resize_handle [ e2c2 aa1a 3a02 fe00 ] -@cursor [ f8e0 e090 8804 0000 ] -@scrollbar [ 0707 0707 0707 0707 ] -@blank [ 0000 0000 0000 0000 ] +@cursor [ f8e0 e090 8804 0000 ] +@scrollbar [ 0707 0707 0707 0707 ] +@bone [ e040 4040 4040 40e0 ] +@blank [ 0000 0000 0000 0000 ] @refresh_button [ 0000 0708 1010 1000 0000 e010 3e1c 0800 @@ -1254,17 +1257,16 @@ JMP2r 0408 191e 1d00 0000 4080 00a8 5000 0000 ] -@bone [ e040 4040 4040 40e0 ] - -@metadata 00 "taro 0a - "v0.2.0 0a +@metadata [ 00 "taro 0a + "v0.2.1 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 +@theme_data [ &r $2 &g $2 &b $2 ] @textbox_text $ff @word $ff -@list_data $8000 @mbox_data $1000 +@list_data $8000