~mil/sxmo-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
7 4

[PATCH] sxmo_hook_tailtextlog.sh: right align and colors

Details
Message ID
<20230504054040.7150-1-projects@jeffkalsow.com>
DKIM signature
missing
Download raw message
Patch: +85 -26
Working from Aren's Pinephone 1.2 fix, I used awk to implement
right alignment(ish), more colors, and easy to modify
time/date format.
---
 .../default_hooks/sxmo_hook_tailtextlog.sh    | 111 ++++++++++++++----
 1 file changed, 85 insertions(+), 26 deletions(-)

diff --git a/configs/default_hooks/sxmo_hook_tailtextlog.sh b/configs/default_hooks/sxmo_hook_tailtextlog.sh
index 51c2109..436035b 100755
--- a/configs/default_hooks/sxmo_hook_tailtextlog.sh
+++ b/configs/default_hooks/sxmo_hook_tailtextlog.sh
@@ -1,4 +1,5 @@
#!/bin/sh
# configversion: 9978740a2faa28d66e2013a837fcf11a
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors

@@ -8,42 +9,100 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

if [ "$1" = format ]; then
	format=true
	shift
fi

LOGDIRNUM="$1"
TERMNAME="$LOGDIRNUM SMS"
export TERMNAME

# If it's already open, switch to it.
if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
fi

mkcontactssedcmd() {
mkcontactscmd() {
	pnc find "$LOGDIRNUM" | while read -r NUMBER; do
		CONTACT="$(sxmo_contacts.sh --name-or-number "$NUMBER")"
		if [ ! "$CONTACT" = "$NUMBER" ]; then
			printf %s "s/$NUMBER/$CONTACT/;"
		fi
		printf "%s" "$NUMBER::$CONTACT:::"
	done
}

# Replace certain dates with human readable versions
TODAY="$(date +%F)"
YESTERDAY="$(date -d "- 1 day" +%F)"
TWO_DAYS="$(date -d "- 2 day" +%F)"
DATESEDCMD="s/at.*${TODAY}T/today at /; s/at.*${YESTERDAY}T/yesterday at /; s/at.*${TWO_DAYS}T/two days ago at /; s/-[0-9][0-9][0-9][0-9]://; s/\(-[0-9][0-9]\)T\([0-9][0-9]\)/\1 \2/;"
format() {
	sleep 1
	# Replace certain dates with human readable versions
	DAY_F="%Y %m %d"
	TIME_F="%H:%M"
	TODAY="$(date "+${DAY_F}")"
	YESTERDAY="$(date -d "- 1 day" "+${DAY_F}")"
	TWO_DAYS="$(date -d "- 2 day" "+${DAY_F}")"

# TODO
#ALIGNSEDCMD="s/^Sent/<right align>/;s/^Received/<left align>/;"
	# Colorize Sent and Received lines
	RECEIVED_COLOR="6"
	RECEIVED_HEAD_COLOR="242"
	SENT_COLOR="4"
	SENT_HEAD_COLOR="242"
	
	tail -n9999 -f "$SXMO_LOGDIR/$LOGDIRNUM/sms.txt" | 
		awk \
		-v contactscmd="$(mkcontactscmd)" \
		-v day_f="$DAY_F" \
		-v time_f="$TIME_F" \
		-v today="$TODAY" \
		-v yesterday="$YESTERDAY" \
		-v two_days="$TWO_DAYS" \
		'
		function print_text(clr,cols){
			printf "%s%*s%s\n",\
			clr,\
			cols,\
			$0,\
			"'`tput op`'";
		}
		{
			# Format send/receive line
			if(/^.*Sent/ || /^.*Received/){
				
				# Remove some bits
				gsub(/(-[0-9]{4}:)|(at )/,"")
				gsub(/[-T:]/," ")

# Colorize Sent and Received lines
RECEIVED_COLOR="2"
SENT_COLOR="3"
COLORSEDCMD="s#^\(Sent.*\)#$(tput setaf "$SENT_COLOR")\1$(tput op)#;s#^\(Received.*\)#$(tput setaf "$RECEIVED_COLOR")\1$(tput op)#;"
				# Format contacts if applies (group messaging)
				split(contactscmd,c,":::")
				for (i=1; i < length(c); i++){
					split(c[i],cc,"::")
					gsub(cc[1],cc[2])
				}

# Replace phone numbers in the filename with contacts from contact book
CONTACTSSEDCMD="$(mkcontactssedcmd)"
				# Format time
				v=substr($0,match($0,/[0-9]{4} [0-9]{1,2} .*[0-9]{1,2}/))
				t=mktime(v)
				gsub(/[0-9]{4} [0-9]{1,2} .*[0-9]{1,2}/,strftime(day_f " " time_f, t))
				gsub(today,"today")
				gsub(yesterday,"yesterday")
				gsub(two_days,"two days ago")
			}
			
			if(/^.*Sent/){
				right_align=1
				print_text("'`tput setaf "$SENT_HEAD_COLOR"`'",'`tput cols`')
			}else if(/^.*Received/){
				right_align=0
				print_text("'`tput setaf "$RECEIVED_HEAD_COLOR"`'")
			}else if(right_align > 0){
				print_text("'`tput setaf "$SENT_COLOR"`'",'`tput cols`')
			}else{
				print_text("'`tput setaf "$RECEIVED_COLOR"`'",0)
			}
		}'  
}

if [ -n "$format" ]; then
	format
	exit 0
fi

# If it's already open, switch to it.
if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
fi

sxmo_terminal.sh sh -c "tail -n9999 -f \"$SXMO_LOGDIR/$LOGDIRNUM/sms.txt\" |\
	sed -e \"$CONTACTSSEDCMD\" -e \"$DATESEDCMD\" -e \"$COLORSEDCMD\""
#sxmo_terminal.sh sh -c "sxmo_hook_parselog.sh \"$NUMBER\""
sxmo_terminal.sh sh -c "$0 format $@"
-- 
2.40.1
Details
Message ID
<ZFOYx3aALhrrwgXn@durand.trilidun.org>
In-Reply-To
<20230504054040.7150-1-projects@jeffkalsow.com> (view parent)
DKIM signature
pass
Download raw message
This is awesome.  Haven't tested it yet, but I noticed:

On Wed, May 03, 2023 at 10:40:40PM -0700, gehn wrote:
>-# If it's already open, switch to it.
>-if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
>-	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
>-	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
>-fi


Why did you comment these lines out?


--
sic dicit magister P
https://phartman.sites.luc.edu/
GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<ZFR4i2-Mnac8Eh-o@jeffkalsow.com>
In-Reply-To
<ZFOYx3aALhrrwgXn@durand.trilidun.org> (view parent)
DKIM signature
missing
Download raw message

On Thu, May 04, 2023 at 11:36:39AM +0000, Hartman, Peter wrote:
> This is awesome.  Haven't tested it yet, but I noticed:
> 
> On Wed, May 03, 2023 at 10:40:40PM -0700, gehn wrote:
> >-# If it's already open, switch to it.
> >-if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
> >-	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
> >-	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
> >-fi
> 
> 
> Why did you comment these lines out?

They are still there, they are below all the new lines.

> 
> 
> --
> sic dicit magister P
> https://phartman.sites.luc.edu/
> GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<ZFjHGDCBSujMQxv+@durand.trilidun.org>
In-Reply-To
<20230504054040.7150-1-projects@jeffkalsow.com> (view parent)
DKIM signature
pass
Download raw message
Thanks, testing locally.  Note sure we'd go with this as a default 
(resizing windows and edge cases have caused problems with alignments 
before), but we might have a 'commented out' version in the hook for 
users to try out if they want... or maybe an SXMO_SMS_ALIGNMENT=1?


On Wed, May 03, 2023 at 10:40:40PM -0700, gehn wrote:
>Working from Aren's Pinephone 1.2 fix, I used awk to implement
>right alignment(ish), more colors, and easy to modify
>time/date format.
>---
> .../default_hooks/sxmo_hook_tailtextlog.sh    | 111 ++++++++++++++----
> 1 file changed, 85 insertions(+), 26 deletions(-)
>
>diff --git a/configs/default_hooks/sxmo_hook_tailtextlog.sh b/configs/default_hooks/sxmo_hook_tailtextlog.sh
>index 51c2109..436035b 100755
>--- a/configs/default_hooks/sxmo_hook_tailtextlog.sh
>+++ b/configs/default_hooks/sxmo_hook_tailtextlog.sh
>@@ -1,4 +1,5 @@
> #!/bin/sh
>+# configversion: 9978740a2faa28d66e2013a837fcf11a
> # SPDX-License-Identifier: AGPL-3.0-only
> # Copyright 2022 Sxmo Contributors
>
>@@ -8,42 +9,100 @@
> # shellcheck source=scripts/core/sxmo_common.sh
> . sxmo_common.sh
>
>+if [ "$1" = format ]; then
>+	format=true
>+	shift
>+fi
>+
> LOGDIRNUM="$1"
> TERMNAME="$LOGDIRNUM SMS"
> export TERMNAME
>
>-# If it's already open, switch to it.
>-if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
>-	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
>-	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
>-fi
>-
>-mkcontactssedcmd() {
>+mkcontactscmd() {
> 	pnc find "$LOGDIRNUM" | while read -r NUMBER; do
> 		CONTACT="$(sxmo_contacts.sh --name-or-number "$NUMBER")"
>-		if [ ! "$CONTACT" = "$NUMBER" ]; then
>-			printf %s "s/$NUMBER/$CONTACT/;"
>-		fi
>+		printf "%s" "$NUMBER::$CONTACT:::"
> 	done
> }
>
>-# Replace certain dates with human readable versions
>-TODAY="$(date +%F)"
>-YESTERDAY="$(date -d "- 1 day" +%F)"
>-TWO_DAYS="$(date -d "- 2 day" +%F)"
>-DATESEDCMD="s/at.*${TODAY}T/today at /; s/at.*${YESTERDAY}T/yesterday at /; s/at.*${TWO_DAYS}T/two days ago at /; s/-[0-9][0-9][0-9][0-9]://; s/\(-[0-9][0-9]\)T\([0-9][0-9]\)/\1 \2/;"
>+format() {
>+	sleep 1
>+	# Replace certain dates with human readable versions
>+	DAY_F="%Y %m %d"
>+	TIME_F="%H:%M"
>+	TODAY="$(date "+${DAY_F}")"
>+	YESTERDAY="$(date -d "- 1 day" "+${DAY_F}")"
>+	TWO_DAYS="$(date -d "- 2 day" "+${DAY_F}")"
>
>-# TODO
>-#ALIGNSEDCMD="s/^Sent/<right align>/;s/^Received/<left align>/;"
>+	# Colorize Sent and Received lines
>+	RECEIVED_COLOR="6"
>+	RECEIVED_HEAD_COLOR="242"
>+	SENT_COLOR="4"
>+	SENT_HEAD_COLOR="242"
>+	
>+	tail -n9999 -f "$SXMO_LOGDIR/$LOGDIRNUM/sms.txt" |
>+		awk \
>+		-v contactscmd="$(mkcontactscmd)" \
>+		-v day_f="$DAY_F" \
>+		-v time_f="$TIME_F" \
>+		-v today="$TODAY" \
>+		-v yesterday="$YESTERDAY" \
>+		-v two_days="$TWO_DAYS" \
>+		'
>+		function print_text(clr,cols){
>+			printf "%s%*s%s\n",\
>+			clr,\
>+			cols,\
>+			$0,\
>+			"'`tput op`'";
>+		}
>+		{
>+			# Format send/receive line
>+			if(/^.*Sent/ || /^.*Received/){
>+				
>+				# Remove some bits
>+				gsub(/(-[0-9]{4}:)|(at )/,"")
>+				gsub(/[-T:]/," ")
>
>-# Colorize Sent and Received lines
>-RECEIVED_COLOR="2"
>-SENT_COLOR="3"
>-COLORSEDCMD="s#^\(Sent.*\)#$(tput setaf "$SENT_COLOR")\1$(tput op)#;s#^\(Received.*\)#$(tput setaf "$RECEIVED_COLOR")\1$(tput op)#;"
>+				# Format contacts if applies (group messaging)
>+				split(contactscmd,c,":::")
>+				for (i=1; i < length(c); i++){
>+					split(c[i],cc,"::")
>+					gsub(cc[1],cc[2])
>+				}
>
>-# Replace phone numbers in the filename with contacts from contact book
>-CONTACTSSEDCMD="$(mkcontactssedcmd)"
>+				# Format time
>+				v=substr($0,match($0,/[0-9]{4} [0-9]{1,2} .*[0-9]{1,2}/))
>+				t=mktime(v)
>+				gsub(/[0-9]{4} [0-9]{1,2} .*[0-9]{1,2}/,strftime(day_f " " time_f, t))
>+				gsub(today,"today")
>+				gsub(yesterday,"yesterday")
>+				gsub(two_days,"two days ago")
>+			}
>+			
>+			if(/^.*Sent/){
>+				right_align=1
>+				print_text("'`tput setaf "$SENT_HEAD_COLOR"`'",'`tput cols`')
>+			}else if(/^.*Received/){
>+				right_align=0
>+				print_text("'`tput setaf "$RECEIVED_HEAD_COLOR"`'")
>+			}else if(right_align > 0){
>+				print_text("'`tput setaf "$SENT_COLOR"`'",'`tput cols`')
>+			}else{
>+				print_text("'`tput setaf "$RECEIVED_COLOR"`'",0)
>+			}
>+		}'
>+}
>+
>+if [ -n "$format" ]; then
>+	format
>+	exit 0
>+fi
>+
>+# If it's already open, switch to it.
>+if [ "$SXMO_WM" = "sway" ] && [ -z "$SSH_CLIENT" ]; then
>+	regesc_termname="$(echo "$TERMNAME" | sed 's|+|\\+|g')"
>+	swaymsg "[title=\"^$regesc_termname\$\"]" focus && exit 0
>+fi
>
>-sxmo_terminal.sh sh -c "tail -n9999 -f \"$SXMO_LOGDIR/$LOGDIRNUM/sms.txt\" |\
>-	sed -e \"$CONTACTSSEDCMD\" -e \"$DATESEDCMD\" -e \"$COLORSEDCMD\""
>-#sxmo_terminal.sh sh -c "sxmo_hook_parselog.sh \"$NUMBER\""
>+sxmo_terminal.sh sh -c "$0 format $@"
>-- 
>2.40.1
>

--
sic dicit magister P
https://phartman.sites.luc.edu/
GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<ZFjx16Qa9nRBPDo8@durand.trilidun.org>
In-Reply-To
<ZFjHGDCBSujMQxv+@durand.trilidun.org> (view parent)
DKIM signature
pass
Download raw message
On Mon, May 08, 2023 at 04:55:37AM -0500, Peter John Hartman wrote:
>Thanks, testing locally.  Note sure we'd go with this as a default 
>(resizing windows and edge cases have caused problems with alignments 
>before), but we might have a 'commented out' version in the hook for 
>users to try out if they want... or maybe an SXMO_SMS_ALIGNMENT=1?
>

Noticed that if I have a text message like this:

Hi, here are some things to be done:
- First, open the door.
- Then, close the door.
- Then, open the door.

This will align everything to the right which breaks up the nice ordered 
list I have made in the text.  I wonder if we should instead keep align 
left but just give it a larger indentation?  Not sure if this is 
possible though with different screen sizes.

--
sic dicit magister P
https://phartman.sites.luc.edu/
GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<ZFkClR7LdlX9_bER@jeffkalsow.com>
In-Reply-To
<ZFjx16Qa9nRBPDo8@durand.trilidun.org> (view parent)
DKIM signature
missing
Download raw message
On Mon, May 08, 2023 at 12:57:59PM +0000, Hartman, Peter wrote:
> On Mon, May 08, 2023 at 04:55:37AM -0500, Peter John Hartman wrote:
> >Thanks, testing locally.  Note sure we'd go with this as a default 
> >(resizing windows and edge cases have caused problems with alignments 
> >before), but we might have a 'commented out' version in the hook for 
> >users to try out if they want... or maybe an SXMO_SMS_ALIGNMENT=1?
> >
I like this idea a lot. Will work on this.
> 
> Noticed that if I have a text message like this:
> 
> Hi, here are some things to be done:
> - First, open the door.
> - Then, close the door.
> - Then, open the door.
> 
> This will align everything to the right which breaks up the nice ordered 
> list I have made in the text.  I wonder if we should instead keep align 
> left but just give it a larger indentation?  Not sure if this is 
> possible though with different screen sizes.

The right alignment is wildly imperfect for sure. In addition to the variable switch for the alignment, i may add an indent variable, which can be 0 or whatever. Ill see what i can do over the next few days.

Thanks for testing this Hartman.
> 
> --
> sic dicit magister P
> https://phartman.sites.luc.edu/
> GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<ZFkS/+3ME+ZpYTNv@durand.trilidun.org>
In-Reply-To
<ZFkClR7LdlX9_bER@jeffkalsow.com> (view parent)
DKIM signature
pass
Download raw message
On Mon, May 08, 2023 at 07:09:25AM -0700, jeff wrote:
>
>On Mon, May 08, 2023 at 12:57:59PM +0000, Hartman, Peter wrote:
>> On Mon, May 08, 2023 at 04:55:37AM -0500, Peter John Hartman wrote:
>> >Thanks, testing locally.  Note sure we'd go with this as a default
>> >(resizing windows and edge cases have caused problems with alignments
>> >before), but we might have a 'commented out' version in the hook for
>> >users to try out if they want... or maybe an SXMO_SMS_ALIGNMENT=1?
>> >
>I like this idea a lot. Will work on this.
>>
>> Noticed that if I have a text message like this:
>>
>> Hi, here are some things to be done:
>> - First, open the door.
>> - Then, close the door.
>> - Then, open the door.
>>
>> This will align everything to the right which breaks up the nice ordered
>> list I have made in the text.  I wonder if we should instead keep align
>> left but just give it a larger indentation?  Not sure if this is
>> possible though with different screen sizes.
>
>The right alignment is wildly imperfect for sure. In addition to the variable switch for the alignment, i may add an indent variable, which can be 0 or whatever. Ill see what i can do over the next few days.
>
>Thanks for testing this Hartman.
>>

A couple further observations:

1. It is pretty slow on big sms.txt files.  Might look to see if you can 
optimize.

2. A couple lines in the patch have extra tabs.  Please remove those :)

3. If Group Chat it only moves me to the right.  I'd have to check what 
other UIs do with group chats, but I'd expect it alternates right / left 
every other participant?

4. One idea for the alignment problem discussed above: Can we assume 
we'll always have 80 characters?  Or can we check that?  If < 80 chars
then revert back to a "basic" view without alignment.  If 80 chars, then 
split at 40 chars: sender align left breaking at 40chars and then 
receive align left starting at 40 chars and breaking at 80chars.  Maybe?

So:

Hi this is an important message.

				 I see.


--
sic dicit magister P
https://phartman.sites.luc.edu/
GPG keyID 0xE0DBD3D6 (CAE6 3A6F 755F 7BC3 36CA  330D B3E6 39C6 E0DB D3D6)
Details
Message ID
<CT4OUEXB5MOS.PAXW9OIZN4EB@yellow-orcess>
In-Reply-To
<20230504054040.7150-1-projects@jeffkalsow.com> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~anjan/sxmo.org
   2ed126e..5118136  main -> main
Reply to thread Export thread (mbox)