~aleteoryx/ntalk

ea7ede93cc7d2e15da60a50428f7f77b53dcf409 — Aleteoryx 2 months ago b1dc906
small fixes and reorg
1 files changed, 46 insertions(+), 44 deletions(-)

M ntalk.tcl
M ntalk.tcl => ntalk.tcl +46 -44
@@ 155,6 155,8 @@ proc sixels2image {sixels} {
	dict set images "sixel:$sixels" $image
	dict set images "xbm:$xbm" $image
	dict set images "image:$image" $sixels
	dict set images "image:motd$image" $sixels
	dict set images "image:mention$image" $sixels

	return $image
}


@@ 201,7 203,7 @@ make16

### UI SETUP ###

label .motd
frame .motd

frame .foot
entry .foot.input


@@ 290,7 292,6 @@ proc setmotd {newmotd} {
	
	set motd $newmotd
}
setmotd "no MOTD yet! maybe you should send one..."


### USER SIXEL LIBRARY ###


@@ 497,48 498,6 @@ proc recvlines {{bd 0}} {
	set inrecv 0
}

proc bufpush {line} {
	global images motd user

	set tag {}
	if {[string first "MOTD:" $line] == 0} {
		setmotd [string trim [string range $line 5 end]]
		set line "<<< $motd >>>"
		set tag motd
	} elseif {[string first "MOTD" $line] == 0} {
		setmotd [string trim [string range $line 4 end]]
		set line "<<< $motd >>>"
		set tag motd
	} elseif {[regexp "\[^\\w.\]${user}\[^\\w.\]" $line]} {
		set tag mention
	}

	.buffer configure -state normal
	foreach {text image} [parseline $line] {
		.buffer insert end $text $tag

		if {$image != {}} {
			lassign $image raw image
			set image $tag$image
			.buffer insert end $raw [concat rawsixel $tag]
			.buffer image create end -image $image
			.buffer tag add $tag {end -1 chars}
		}
	}
	.buffer insert end "\n" $tag
	.buffer configure -state disabled
}
proc bufdown {} {
	.buffer yview moveto 1
	update
}
proc bufclear {} {
	.buffer configure -state normal
	.buffer replace 1.0 end {}
	.buffer configure -state disabled
	update
}

proc send {line} {
	sendl "SEND $line"
	recvl


@@ 585,6 544,49 @@ proc stat {} {

### ACTUAL CLIENT CODE LMAO ###

proc bufpush {line} {
	global images motd user

	set tag {}
	if {[string first "MOTD:" $line] == 0} {
		setmotd [string trim [string range $line 5 end]]
		set line "<<< $motd >>>"
		set tag motd
	} elseif {[string first "MOTD" $line] == 0} {
		setmotd [string trim [string range $line 4 end]]
		set line "<<< $motd >>>"
		set tag motd
	} elseif {[regexp "\[^\\w.\]${user}\[^\\w.\]" $line]} {
		set tag mention
	}

	.buffer configure -state normal
	foreach {text image} [parseline $line] {
		.buffer insert end $text $tag

		if {$image != {}} {
			lassign $image raw image
			set image $tag$image
			.buffer insert end $raw [concat rawsixel $tag]
			.buffer image create end -image $image
			.buffer tag add $tag {end -1 chars}
		}
	}
	.buffer insert end "\n" $tag
	.buffer configure -state disabled
}
proc bufdown {} {
	.buffer yview moveto 1
	update
}
proc bufclear {} {
	.buffer configure -state normal
	.buffer replace 1.0 end {}
	.buffer configure -state disabled
	setmotd "no MOTD yet! maybe you should send one..."
	update
}

proc sendmsg {msg} {
	global lastmsg
	set msgid [send $msg]