shell out for reader and compose windows - this should work for a while; v0.1.0

This commit is contained in:
Iris Lightshard 2023-03-23 07:44:41 -06:00
parent 87cb90db9b
commit a795631f8a
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
5 changed files with 189 additions and 41 deletions

View file

@ -1,6 +1,14 @@
# taro
`mblaze` frontend in `uxn` and `crystal`
[mblaze](https://git.vuxu.org/mblaze) frontend in [uxn](https://wiki.xxiivv.com/site/uxn.html) and [crystal](https://crystal-lang.org)
## build and install
1. [Configure mblaze](https://git.vuxu.org/mblaze/about/man/mblaze-profile.5)
2. Install [uxn](https://git.sr.ht/~rabbits/uxn) and [crystal](https://crystal-lang.org/install/)
3. Edit [conf.cr](./conf.cr) and probably the `handle` function in [mread](./mread)
4. Run [build.sh](./build.sh)
5. Copy `taro-ctl` to your path
## messages
@ -20,4 +28,6 @@ Odd messages go from the `uxn` windows to `taro-ctl`.
- `3`: mark all as read in current mailbox; no payload
- `5`: search mail; payload is the regex
- `7`: refile mail; payload is the beginning and end of the mmsg range in u16, and then the mailbox name
- `9`: trash mail; payload is the beginning and end of the mmsg range in u16
- `9`: trash mail; payload is the beginning and end of the mmsg range in u16
- `11`: read mail; payload is a single u16 message number in the current sequence
- `13`: compose mail; no payload

3
conf.cr Normal file
View file

@ -0,0 +1,3 @@
TARO_LIB = "/home/nilix/src/taro/"
READER_PROG = "st -t \"taro-reader\" -e #{TARO_LIB}/mread"
COMPOSE_PROG = "st -t \"taro-compose\" -e mcom"

74
mread Executable file
View file

@ -0,0 +1,74 @@
#!/bin/sh
mhandle() {
case $2 in
text/html)
cp $1 ${1}.html
netsurf ${1}.html
rm ${1}.html;;
image/*)
qiv $1;;
audio/*|video/*)
mpv $1;;
pgp/encrypted)
gpg --decrypt $1;;
application/vnd*)
libreoffice $1;;
application/pdf)
zathura $1;;
esac
}
_mread() {
local META
local this=$(mseq $@)
mflag -S ${this}
while true; do
mshow ${this}
while true; do
META=""
printf "\n"
mshow -t
printf "\n"
printf "[1..n] view attachment (add s to save)\n"
printf "[r]reply, [f]orward, [q]uit\n"
read cmd
case ${cmd} in
1|2|3|4|5|6|7|8|9|10|\
11|12|13|14|15|16|17|18|19|20)
attachment=$(mktemp)
mshow -O . ${cmd} > ${attachment}
mimetype=$(mshow -t | grep ${cmd}: | awk '{print $2}')
mhandle ${attachment} ${mimetype}
rm ${attachment};;
1s|2s|3s|4s|5s|6s|7s|8s|9s|10s|\
11s|12s|13s|14s|15s|16s|17s|18s|19s|20s)
mshow -x . ${cmd%s};;
q|quit)
META=q;;
r|reply)
META=r;;
f|forward)
META=f;;
esac
[ ! -z "${META}" ] && break;
done
this="."
case ${META} in
f)
mfwd ${this};;
r)
mrep ${this};;
q)
return;;
*)
;;
esac
mseq -f | mseq -S
done
}
_mread $@

View file

@ -2,6 +2,13 @@ require "process"
require "io/memory"
require "io"
require "./conf"
MSG_SIZES = {
0_u8 => 4096_u16,
2_u8 => 32768_u16,
}
def u8arr_tou16(s : Slice(UInt8)) : UInt16
if s.size < 2
return 0_u16
@ -53,7 +60,7 @@ module Taro
@sizing : Bool = false
@szshort : UInt16 = 0
def initialize(w : WinType = WinType::LIST)
def initialize(w : WinType = WinType::LIST, arg : String = "")
@stdout_r, @stdout_w = IO.pipe
@stdin_r, @stdin_w = IO.pipe
@lifetime = Channel(UInt8).new
@ -68,17 +75,30 @@ module Taro
when WinType::COMPOSE then uxnrom = "taro-compose"
end
uxnargs = ["-s", "1", "#{uxnrom}.rom"]
spawn do
Process.run(command: "uxnemu", args: uxnargs, input: @stdin_r, output: @stdout_w, error: Process::Redirect::Inherit)
@lifetime.send(0)
end
spawn do
loop do
@@msg.send(read_msg)
uxnargs = ["-s", "1", "#{TARO_LIB}/#{uxnrom}.rom"]
case w
when WinType::LIST then
spawn do
Process.run(command: "uxnemu", args: uxnargs, input: @stdin_r, output: @stdout_w, error: Process::Redirect::Inherit)
@lifetime.send(0)
end
spawn do
loop do
@@msg.send(read_msg)
end
end
when WinType::READER then
spawn do
Process.run(command: READER_PROG + " " + arg, shell: true)
@@msg.send(Mesg.new(1_u8, MblazeProxy.mailbox.to_slice))
end
when WinType::COMPOSE then
spawn do
Process.run(command: COMPOSE_PROG, shell: true)
@@msg.send(Mesg.new(1_u8, MblazeProxy.mailbox.to_slice))
end
end
end
def id
@ -90,11 +110,13 @@ module Taro
end
def write_msg(msgtype : UInt8, data : Slice)
msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size)
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)
msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian)
if msgsz == 16384
if msgsz == MSG_SIZES[msgtype]
@stdin_w.write(data[0..msgsz - 2])
10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian)
elsif msgsz != 0
@ -141,10 +163,10 @@ module Taro
end
class MblazeProxy
@mailbox : String
@@mailbox : String = "INBOX"
def initialize
@mailbox = "INBOX"
def self.mailbox
@@mailbox
end
private def run_cmd(cmdtxt : String) : String
@ -156,7 +178,7 @@ module Taro
def list_mail : String
cmd = "
mbox=${MBOX_ROOT}/#{@mailbox}
mbox=${MBOX_ROOT}/#{@@mailbox}
mdirs ${mbox} | xargs minc > /dev/null
mlist ${mbox} | msort -dr | mseq -S | mscan"
@ -176,14 +198,14 @@ module Taro
end
def set_mbox(box : String)
@mailbox = box
@@mailbox = box
end
def trash_mail(range_start : UInt16, range_end : UInt16)
cmd = "mrefile #{range_start}:#{range_end} ${MBOX_ROOT}/Trash"
# destroy mail if we are trashing what's already in the trash!
if @mailbox == "Trash"
if @@mailbox == "Trash"
cmd = "for x in $(mseq #{range_start}:#{range_end}); do rm $x; done"
end
run_cmd(cmd)
@ -195,7 +217,7 @@ module Taro
end
def search_mail(query : String, body : Bool) : String
cmd = "mlist ${MBOX_ROOT}/#{@mailbox} | magrep #{body ? "/" : "*"}:#{query} | msort -dr | uniq | mseq -S | mscan"
cmd = "mlist ${MBOX_ROOT}/#{@@mailbox} | magrep #{body ? "/" : "*"}:#{query} | msort -dr | uniq | mseq -S | mscan"
return run_cmd(cmd)
end
end
@ -266,6 +288,11 @@ loop do
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)
end
end
end

View file

@ -9,6 +9,8 @@
%SEARCH_MAIL { #05 }
%REFILE_MAIL { #07 }
%TRASH_MAIL { #09 }
%READ_MAIL { #0b }
%COMPOSE_MAIL { #0d }
( UI constants )
@ -96,7 +98,7 @@
#03 .btn_colors/refile STZ
#03 .btn_colors/trash STZ
;noop_button_click .btn_fns/compose STZ2
;send_compose .btn_fns/compose STZ2
;send_get_mbox .btn_fns/refresh STZ2
;send_mark_all_read .btn_fns/read_all STZ2
;enter_search_mode .btn_fns/search STZ2
@ -240,6 +242,23 @@ JMP2r
JMP2r
@send_reader ( -> )
READ_MAIL .Console/write DEO
#0002 SWP .Console/write DEO .Console/write DEO
.list LB_SELECT_IDX LDZ2 SWP .Console/write DEO .Console/write DEO
JMP2r
@send_compose ( -> )
COMPOSE_MAIL .Console/write DEO
#00 .Console/write DEOk DEO
( message size is 0, no payload )
JMP2r
@send_str ( str* -- )
&while
@ -287,13 +306,13 @@ JMP2r
enter_refile_mode
&no_refile
DUP #6e NEQ ,&no_compose JCN
( awaiting compose window implementation )
send_compose
&no_compose
DUP #2e NEQ ,&no_all_read JCN
send_mark_all_read
&no_all_read
DUP #0d NEQ ,&no_reader JCN
( awaiitng reader window implementation )
send_reader
&no_reader
DUP #09 NEQ ,&no_tab JCN
( check shift or not - prev mailbox if so, otherwise next )
@ -305,7 +324,6 @@ JMP2r
&no_up
DUP #20 NEQ ,&no_down JCN
&no_down
POP
BRK
@handle_textbox ( -> )
@ -415,8 +433,8 @@ JMP2r
@on_mouse ( -> )
;mbox_select_handler .mboxes .refresh/mboxes #0000 #00 mouse_event_list
;noop_list_click .list .refresh/list TOP_SECTION MID_SEPARATOR ADD2 #04 mouse_event_list
;noop_list_click ;mbox_select_handler .mboxes .refresh/mboxes #0000 #00 mouse_event_list
;right_click_mail_list ;noop_list_click .list .refresh/list TOP_SECTION MID_SEPARATOR ADD2 #04 mouse_event_list
.btn_fns .btn_colors SUB mouse_event_buttons
.resizing LDZ #00 EQU ,&resz_check JCN
@ -508,7 +526,7 @@ JMP2r
JMP2r
@mouse_event_list ( clickhandler* list refresh ypos* multiselect -- )
@mouse_event_list ( rightclickhanlder* clickhandler* list refresh ypos* multiselect -- )
,&multi STR
,&y STR2
@ -516,9 +534,9 @@ JMP2r
STH
( check bounds )
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 GTH2 ,&done JCN
.Mouse/y DEI2 ,&y LDR2 LTH2 ,&done JCN
.Mouse/y DEI2 ,&y LDR2 [ STHkr LB_HEIGHT LDZ #00 SWP #30 SFT2 ] ADD2 #0001 SUB2 GTH2 ,&done JCN
.Mouse/x DEI2 .Screen/width DEI2 #0008 SUB2 GTH2 ,&almost_done JCN
.Mouse/y DEI2 ,&y LDR2 LTH2 ,&almost_done JCN
.Mouse/y DEI2 ,&y LDR2 [ STHkr LB_HEIGHT LDZ #00 SWP #30 SFT2 ] ADD2 #0001 SUB2 GTH2 ,&almost_done JCN
( check scrollwheel )
.Mouse/scrolly DEI2 #0000 EQU2 ,&no_scroll JCN
@ -528,28 +546,37 @@ JMP2r
STHkr try_scroll_up_mouse
,&no_scroll JMP
&almost_done
,&done JMP
( data )
&multi $1
&y $2
&r $1
&scroll_down
STHkr try_scroll_down_mouse
&no_scroll
.Mouse/state DEI #01 AND #00 EQU ,&done JCN
( leftclick )
.Mouse/state DEI #05 AND #00 EQU ,&done JCN
,&multi LDR ,&y LDR2 STHkr mouse_select_on_click
.Mouse/state DEI #01 AND #00 EQU ,&no_left JCN
( leftclick )
STHr ROT ROT JSR2
POP2
#01 ,&r LDR STZ
JMP2r
( data )
&y $2
&r $1
&no_left
.Mouse/state DEI #04 AND #00 EQU ,&no_right JCN
( rightclick )
STHr POP2 ROT ROT JSR2
#01 ,&r LDR STZ
JMP2r
&no_right
&done
#01 ,&r LDR STZ
POPr
POP2
POP2
JMP2r
@ -643,6 +670,13 @@ JMP2r
JMP2r
@right_click_mail_list ( list -- )
send_reader
JMP2r
@try_scroll_up_mouse ( list -- )
STH
@ -1075,5 +1109,5 @@ JMP2r
@textbox_text $ff
@word $ff
@selected_mbox "INBOX 00 $f9 ( default mailbox is INBOX, total space #06 + #f9 = #ff bytes )
@list_data $4000
@mbox_data $4000
@list_data $8000
@mbox_data $1000