ref: b697e8655a2f0ef5cb0ad26844f1264334a416f1
parent: e2ed2a0b7efda6ac1a93071e77e93dea0fa6d983
author: cinap_lenrek <[email protected]>
date: Thu Oct 20 07:29:27 EDT 2011
mothra: fix alt display resizing, filter control characters in panel entries, use uslstr() instead of selection->fullname as fullname gets truncated in selurl()
--- a/sys/src/cmd/mothra/libpanel/edit.c
+++ b/sys/src/cmd/mothra/libpanel/edit.c
@@ -19,6 +19,8 @@
#include <event.h>
#include <panel.h>
#include "pldefs.h"
+#include <keyboard.h>
+
typedef struct Edit Edit;
struct Edit{
Point minsize;
@@ -122,15 +124,15 @@
t->b=p->b;
twhilite(t, ep->sel0, ep->sel1, 0);
switch(c){
- case '\b':
+ case Kbs: /* ^H: erase character */
if(ep->sel0!=0) --ep->sel0;
twreplace(t, ep->sel0, ep->sel1, 0, 0);
break;
- case '\025': /* ctrl-u */
+ case Knack: /* ^U: erase line */
while(ep->sel0!=0 && t->text[ep->sel0-1]!='\n') --ep->sel0;
twreplace(t, ep->sel0, ep->sel1, 0, 0);
break;
- case '\027': /* ctrl-w */
+ case Ketb: /* ^W: erase word */
while(ep->sel0!=0 && !pl_idchar(t->text[ep->sel0-1])) --ep->sel0;
while(ep->sel0!=0 && pl_idchar(t->text[ep->sel0-1])) --ep->sel0;
twreplace(t, ep->sel0, ep->sel1, 0, 0);
--- a/sys/src/cmd/mothra/libpanel/entry.c
+++ b/sys/src/cmd/mothra/libpanel/entry.c
@@ -4,6 +4,8 @@
#include <event.h>
#include <panel.h>
#include "pldefs.h"
+#include <keyboard.h>
+
typedef struct Entry Entry;
struct Entry{
char *entry;
@@ -47,15 +49,15 @@
*ep->entp='\0';
if(ep->hit) ep->hit(p, ep->entry);
return;
- case 025: /* ctrl-u */
+ case Knack: /* ^U: erase line */
ep->entp=ep->entry;
*ep->entp='\0';
break;
- case '\b':
+ case Kbs: /* ^H: erase character */
while(ep->entp!=ep->entry && !pl_rune1st(ep->entp[-1])) *--ep->entp='\0';
if(ep->entp!=ep->entry) *--ep->entp='\0';
break;
- case 027: /* ctrl-w */
+ case Ketb: /* ^W: erase word */
while(ep->entp!=ep->entry && !pl_idchar(ep->entp[-1]))
--ep->entp;
while(ep->entp!=ep->entry && pl_idchar(ep->entp[-1]))
@@ -63,6 +65,8 @@
*ep->entp='\0';
break;
default:
+ if(c < 0x20 || c == Kesc || c == Kdel || (c & 0xFF00) == KF || (c & 0xFF00) == Spec)
+ break;
ep->entp+=runetochar(ep->entp, &c);
if(ep->entp>ep->eent){
n=ep->entp-ep->entry;
@@ -77,8 +81,6 @@
break;
}
memset(ep->entp, 0, SLACK);
-
- /* strcpy(ep->entp, "◀"); */
pldraw(p, p->b);
}
Point pl_getsizeentry(Panel *p, Point children){
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -92,6 +92,7 @@
int mothmode;
void docmd(Panel *, char *);
void doprev(Panel *, int, int);
+char *urlstr(Url *);
void selurl(char *);
void setcurrent(int, char *);
char *genwww(Panel *, int);
@@ -449,6 +450,7 @@
plinitlabel(curttl, PACKE|EXPAND, "---");
plinitlabel(cururl, PACKE|EXPAND, "---");
plpack(root, r);
+ plpack(alt, r);
if(current){
plinitlabel(curttl, PACKE|EXPAND, current->title);
plinitlabel(cururl, PACKE|EXPAND, current->url->fullname);
@@ -611,10 +613,8 @@
char *name, *slash;
if(url == nil)
return nil;
- if(url->fullname[0])
- name = url->fullname;
- else if(url->reltext[0])
- name = url->reltext;
+ if(url->fullname[0] || url->reltext[0])
+ name = urlstr(url);
else
name = "/";
if(slash = strrchr(name, '/'))
@@ -647,12 +647,13 @@
case 'g':
s = arg(s);
if(*s=='\0'){
+ case 'r':
if(selection)
- geturl(selection->fullname, GET, 0, 0, 0);
+ s = urlstr(selection);
else
message("no url selected");
}
- else geturl(s, GET, 0, 0, 0);
+ geturl(s, GET, 0, 0, 0);
break;
case 'j':
s = arg(s);
@@ -661,11 +662,6 @@
else
message("Usage: j index");
break;
- case 'r':
- s = arg(s);
- if(*s=='\0' && selection)
- geturl(selection->fullname, GET, 0, 0, 0);
- break;
case 'W':
s = arg(s);
if(s=='\0'){
@@ -684,15 +680,17 @@
break;
case 's':
s = arg(s);
- if(selection){
- if(s==0 || *s=='\0')
- s = urltofile(selection);
- if(s==0 || *s=='\0'){
- message("Usage: s file");
- break;
- }
- save(urlopen(selection, GET, 0), s);
+ if(!selection){
+ message("no url selected");
+ break;
}
+ if(s==0 || *s=='\0')
+ s = urltofile(selection);
+ if(s==0 || *s=='\0'){
+ message("Usage: s file");
+ break;
+ }
+ save(urlopen(selection, GET, 0), s);
break;
case 'q':
draw(screen, screen->r, display->white, 0, ZP);
@@ -927,9 +925,14 @@
return pfd[1];
}
-/*
- * select the file at the given url
- */
+char*
+urlstr(Url *url){
+ if(url->fullname[0])
+ return url->fullname;
+ if(url->reltext[0])
+ return url->reltext;
+ return nil;
+}
void selurl(char *urlname){
static Url url;
seturl(&url, urlname, current?
@@ -936,7 +939,7 @@
current->url->fullname :
defurl.fullname);
selection=&url;
- message("selected: %s", selection->fullname[0] ? selection->fullname : selection->reltext);
+ message("selected: %s", urlstr(selection));
}
void seturl(Url *url, char *urlname, char *base){
strncpy(url->reltext, urlname, sizeof(url->reltext));
@@ -1126,7 +1129,7 @@
int fd;
fd=create("/dev/snarf", OWRITE, 0666);
if(fd>=0){
- fprint(fd, "%s", selection->fullname[0] ? selection->fullname : selection->reltext);
+ fprint(fd, "%s", urlstr(selection));
close(fd);
}
}
@@ -1187,8 +1190,7 @@
fprint(fd, "<body><h1>Hit list</h1>\n");
}
seek(fd, 0, 2);
- fprint(fd, "<p><a href=\"%s\">%s</a>\n",
- selection->fullname, selection->fullname);
+ fprint(fd, "<p><a href=\"%s\">%s</a>\n", urlstr(selection), urlstr(selection));
close(fd);
break;
case 5: