9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Command to set samterm label
@ 2021-07-18 18:06 adr via 9fans
  2021-07-18 20:26 ` umbraticus
  0 siblings, 1 reply; 6+ messages in thread
From: adr via 9fans @ 2021-07-18 18:06 UTC (permalink / raw)
  To: 9fans

Hi,

I was hacking sam to set /dev/label to 'sam filename' when one is
given to be opened but then I thought that it would be better to
make samterm do it, so it'll work when using sam remotely.

This patch adds a command 'l' to set the label, and sets it at
startup as described above.

Regards,
adr.

--- sys/src/cmd/sam/cmd.c       Wed Apr 24 00:06:05 2013
+++ /sys/src/cmd/sam/cmd.c      Sun Jul 18 18:23:06 2021
@@ -17,6 +17,7 @@
        'g',    0,      1,      0,      'p',    aDot,   0,      0,      g_cmd,
        'i',    1,      0,      0,      0,      aDot,   0,      0,      i_cmd,
        'k',    0,      0,      0,      0,      aDot,   0,      0,      k_cmd,
+       'l',    0,      0,      0,      0,      aNo,    0,      linex,  l_cmd,
        'm',    0,      0,      1,      0,      aDot,   0,      0,      m_cmd,
        'n',    0,      0,      0,      0,      aNo,    0,      0,      n_cmd,
        'p',    0,      0,      0,      0,      aDot,   0,      0,      p_cmd,
--- sys/src/cmd/sam/mesg.h      Fri Mar 18 22:33:33 2005
+++ /sys/src/cmd/sam/mesg.h     Sun Jul 18 18:25:36 2021
@@ -67,6 +67,7 @@
        Hack,           /* request acknowledgement */
        Hexit,
        Hplumb,         /* return plumb message to terminal - version 1 */
+       Hlabel, /* change /dev/label */
        HMAX,
  }Hmesg;
  typedef struct Header{
--- sys/src/cmd/sam/parse.h     Thu Oct 27 15:36:34 2005
+++ /sys/src/cmd/sam/parse.h    Sat Jul 17 19:55:51 2021
@@ -55,13 +55,12 @@

  int   nl_cmd(File*, Cmd*), a_cmd(File*, Cmd*), b_cmd(File*, Cmd*);
  int   c_cmd(File*, Cmd*), cd_cmd(File*, Cmd*), d_cmd(File*, Cmd*);
-int    D_cmd(File*, Cmd*), e_cmd(File*, Cmd*);
-int    f_cmd(File*, Cmd*), g_cmd(File*, Cmd*), i_cmd(File*, Cmd*);
-int    k_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
-int    p_cmd(File*, Cmd*), q_cmd(File*, Cmd*);
-int    s_cmd(File*, Cmd*), u_cmd(File*, Cmd*), w_cmd(File*, Cmd*);
-int    x_cmd(File*, Cmd*), X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*);
-int    eq_cmd(File*, Cmd*);
+int    D_cmd(File*, Cmd*), e_cmd(File*, Cmd*), f_cmd(File*, Cmd*);
+int    g_cmd(File*, Cmd*), i_cmd(File*, Cmd*), k_cmd(File*, Cmd*);
+int    l_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
+int    p_cmd(File*, Cmd*), q_cmd(File*, Cmd*), s_cmd(File*, Cmd*);
+int    u_cmd(File*, Cmd*), w_cmd(File*, Cmd*), x_cmd(File*, Cmd*);
+int    X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*), eq_cmd(File*, Cmd*);


  String        *getregexp(int);
--- sys/src/cmd/sam/sam.c       Tue Dec  6 17:05:45 2005
+++ /sys/src/cmd/sam/sam.c      Sat Jul 17 17:01:44 2021
@@ -98,6 +98,8 @@
        seq++;
        if(file.nused)
                current(file.filepptr[0]);
+       if(curfile)
+               outTS(Hlabel, &(curfile->name));
        setjmp(mainloop);
        cmdloop();
        trytoquit();    /* if we already q'ed, quitok will be TRUE */
--- sys/src/cmd/sam/xec.c       Tue Jun  6 02:55:54 2000
+++ /sys/src/cmd/sam/xec.c      Sat Jul 17 20:20:41 2021
@@ -154,6 +154,14 @@
  }

  int
+l_cmd(File *f, Cmd *cp)
+{
+       USED(f);
+       outTS(Hlabel, cp->ctext);
+       return TRUE;
+}
+
+int
  m_cmd(File *f, Cmd *cp)
  {
        Address addr2;
--- sys/src/cmd/samterm/mesg.c  Thu Mar 29 19:35:49 2012
+++ /sys/src/cmd/samterm/mesg.c Sat Jul 17 20:28:26 2021
@@ -97,6 +97,7 @@
        int i, m;
        long l;
        Flayer *lp;
+       char *str, c;

        m = inshort(0);
        l = inlong(2);
@@ -106,6 +107,16 @@
        default:
                fprint(2, "type %d\n", type);
                panic("rcv unknown");
+
+       case Hlabel:
+               str = (char *)indata;
+               if((i = open("/dev/label", OWRITE)) >= 0){
+                       while((c=*str) == ' ' || c=='\t')
+                               str++;
+                       fprint(i, "%s %s", "sam", str);
+                       close(i);
+               }
+               break;

        case Hversion:
                hversion = m;


------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M6011c83bf34acbf24c11966a
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] Command to set samterm label
  2021-07-18 18:06 [9fans] Command to set samterm label adr via 9fans
@ 2021-07-18 20:26 ` umbraticus
  2021-07-18 21:58   ` adr via 9fans
  0 siblings, 1 reply; 6+ messages in thread
From: umbraticus @ 2021-07-18 20:26 UTC (permalink / raw)
  To: 9fans

> This patch adds a command 'l' to set the label, and sets it at
> startup as described above.

meh; you can already run !label blah from inside sam
not sure the label-on-startup adds much…
but I guess you could just add that at the call to initdraw.

umbraticus

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M8c02d90b20788e858568ad92
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] Command to set samterm label
  2021-07-18 20:26 ` umbraticus
@ 2021-07-18 21:58   ` adr via 9fans
  2021-07-18 22:39     ` umbraticus
  2021-07-19  0:51     ` adr via 9fans
  0 siblings, 2 replies; 6+ messages in thread
From: adr via 9fans @ 2021-07-18 21:58 UTC (permalink / raw)
  To: 9fans

On Mon, 19 Jul 2021, umbraticus@prosimetrum.com wrote:
>> This patch adds a command 'l' to set the label, and sets it at
>> startup as described above.
>
> meh; you can already run !label blah from inside sam

That's run by sam, not samterm.

> not sure the label-on-startup adds much?

It's for using multimple instances of sam.

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M1b37b0e9f704fadce4e61f64
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] Command to set samterm label
  2021-07-18 21:58   ` adr via 9fans
@ 2021-07-18 22:39     ` umbraticus
  2021-07-19  0:51     ` adr via 9fans
  1 sibling, 0 replies; 6+ messages in thread
From: umbraticus @ 2021-07-18 22:39 UTC (permalink / raw)
  To: 9fans

> That's run by sam, not samterm.

Ah, I see; /dev/label is not available to the remote end of sam -r.
Do people use sam -r a lot, instead of [r]cpu -c sam?
Is it appreciably faster? surely having /mnt/term & local /dev
in the namespace is nice?  Anyway, I see your point.

Still not convinced setting the window label belongs inside
the editor (or the editor's wm) since it is a feature of rio...
If you use winwatch some have patched it to make setting
label more convenient, or you could have a script that does:

; label sam $files; bind /dev/null /dev/label; sam $files

I discovered this trick when I wanted my persistent page
always to be labeled as such rather than change based on
whatever it is displaying.

> It's for using multimple instances of sam.

Sure, was just pointing out if !label was sufficient you could
simplify your patch to just tweaking the initdraw call.
(Maybe it would be nice to print all files listed on the command line)

On the odd occasion I have multiple sams, I prefer to set the label
myself to project1, project2 &c. but having the filename(s) there
initially might be nice.  You could even get clever and have
the label change to reflect the most recently active buffer.

umbraticus

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M1e8dc73ec3b6f44f7e047e5b
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] Command to set samterm label
  2021-07-18 21:58   ` adr via 9fans
  2021-07-18 22:39     ` umbraticus
@ 2021-07-19  0:51     ` adr via 9fans
  2021-07-19 11:59       ` umbraticus
  1 sibling, 1 reply; 6+ messages in thread
From: adr via 9fans @ 2021-07-19  0:51 UTC (permalink / raw)
  To: 9fans

Ok, Let me explain this a little.

I don't like this "One X to rule them all" concept, recreating
complete interfaces. I would prefer to use one gui, and make the
programs integrate in it, rethinking some concepts if necessary.

Been able to modify the label is fundamental for this. It's a
way to identify the program and show its state. Just the same
sam does inside its own duplicated interface.

The correct way to do this is respecting the program design. That's
why the label must be changed in the samterm side.

This little change allows you to open a file with one instance of
sam, another file with another instance (just not use plumb to
edit...) and be able to identify them, using the gui you already
have, rio. And if for example you open another file because you
need them stuck side by side (but this should be done by gui,
not by the editor...) you still can rename the label manually to
reflect the change.

The next step is add an option (or better an environment variable)
to use the rio snarf buffer directly.

If you don't see the point of this, just ignore this thread.

I'm sharing this patch just in case someone is so frustrated as me
with this design, nothing more.

By the way, sam -r allows you to edit remotely a file in a unix
system, not only with p9p sam, samterm will drive even the old sam
from pkgsrc.  Running samterm locally is way more efficient than
using X forwarding.

Regards,
adr.

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M4075dd8b5bd996932f445643
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] Command to set samterm label
  2021-07-19  0:51     ` adr via 9fans
@ 2021-07-19 11:59       ` umbraticus
  0 siblings, 0 replies; 6+ messages in thread
From: umbraticus @ 2021-07-19 11:59 UTC (permalink / raw)
  To: 9fans

Sorry, didn't mean to come off as insisting you had to do it
my way (I am guilty of hacking all kinds of things into my
own samterm); just wanted to point out there are other ways
besides adding a new command to sam.

> The next step is add an option (or better an environment variable)
> to use the rio snarf buffer directly.

There is a patch for this floating around somewhere: perhaps
whoever wrote it can chime in.

Below is a quick illustration of the other thought I had,
having label reflect the most recently topped buffer, in
case you are or anyone else is interested.

umbraticus

diff -u /sys/src/cmd/samterm/main.c ./main.c
--- /sys/src/cmd/samterm/main.c Thu Apr 30 10:24:09 2020
+++ ./main.c    Mon Jul 19 23:36:12 2021
@@ -150,6 +150,7 @@
 current(Flayer *nw)
 {
        Text *t;
+       int fd;
 
        if(which)
                flborder(which, 0);
@@ -160,8 +161,13 @@
                buttons(Up);
                t = (Text *)nw->user1;
                t->front = nw-&t->l[0];
-               if(t != &cmd)
+               if(t != &cmd){
                        work = nw;
+                       if((fd = open("/dev/label", OWRITE)) >= 0){
+                               fprint(fd, "sam %s", (char*)name[whichmenu(t->tag)] + 1);
+                               close(fd);
+                       }
+               }
        }
        which = nw;
 }
@@ -170,11 +176,15 @@
 closeup(Flayer *l)
 {
        Text *t=(Text *)l->user1;
-       int m;
+       int m, fd;
 
        m = whichmenu(t->tag);
        if(m < 0)
                return;
+       if((fd = open("/dev/label", OWRITE)) >= 0){
+               write(fd, "sam", 4);
+               close(fd);
+       }
        flclose(l);
        if(l == which){
                which = 0;

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tf1e211daf823c0e0-M2dfbf5d65c86fcf89c315484
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-19 11:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18 18:06 [9fans] Command to set samterm label adr via 9fans
2021-07-18 20:26 ` umbraticus
2021-07-18 21:58   ` adr via 9fans
2021-07-18 22:39     ` umbraticus
2021-07-19  0:51     ` adr via 9fans
2021-07-19 11:59       ` umbraticus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).