[RFC, PATCH] new applet resize #2
Bernhard Fischer
rep.nop at aon.at
Thu Sep 21 21:04:54 UTC 2006
On Thu, Sep 21, 2006 at 10:17:44PM +0200, Bernhard Fischer wrote:
>On Thu, Sep 21, 2006 at 02:04:13PM -0400, Rich Felker wrote:
>>On Thu, Sep 21, 2006 at 07:35:52PM +0200, Bernhard Fischer wrote:
>
>>IMO (and I seem recall someone else in the thread saying the same)
>>setting the variables is not a good idea anyway, so it's probably not
>>useful to print these.
>>
>>> That's what you get if you write a quick, bloated hack for somebody
>>> else, i guess ;)
>>>
>>> I'm not even sure if something like this should go into busybox and
>>> if so then where to put it. console-tools? miscutils?
>>> /me fanciless ATM
>>
>>Yeah somewhere like that, I suppose. And if it's going in BB there's
>>no problem with using stdio, etc. since they'll already be linked
>>anyway. Avoiding them is only useful for tiny standalone programs.
>
>The attached should actually work for settion the w/h.
>Dave, can you test this please?
>
>Rob, do we want this applied after somebody quickly checked that it's
>doing what it is supposed to do?
>
>stats:
>(with IMA mode, bloatcheck):
>function old new delta
>resize_main - 220 +220
>.rodata 174048 174096 +48
>static.check_mntent_file 760 776 +16
>static.e2fsck_pass1 7804 7816 +12
>evaltreenr 623 633 +10
>evaltree 623 633 +10
>static.add_interface 300 302 +2
>static.qrealloc 45 44 -1
>static.glob3 37 35 -2
>busybox_main 472 470 -2
>static.popstring 150 147 -3
>static.parse_opts 61 56 -5
>static.diffreg 2945 2938 -7
>static.new_init_module 505 497 -8
>ext2fs_open_inode_scan 403 391 -12
>ed_main 3348 3323 -25
>------------------------------------------------------------------------------
>(add/remove: 1/0 grow/shrink: 6/9 up/down: 318/-65) Total: 253 bytes
>
>(IMA, size)
>$ size busybox_old busybox
> text data bss dec hex filename
> 823938 6436 239444 1069818 1052fa busybox_old
> 824224 6440 239444 1070108 10541c busybox
>
>
>(legacy, size)
>$ size console-tools/resize.o
> text data bss dec hex filename
> 254 0 0 254 fe console-tools/resize.o
And without being actively stoopid:
text data bss dec hex filename
223 0 0 223 df console-tools/resize.o
-------------- next part --------------
Index: console-tools/Makefile.in
===================================================================
--- console-tools/Makefile.in (revision 16161)
+++ console-tools/Makefile.in (working copy)
@@ -20,6 +20,7 @@ CONSOLETOOLS-$(CONFIG_LOADFONT) += loadf
CONSOLETOOLS-$(CONFIG_LOADKMAP) += loadkmap.o
CONSOLETOOLS-$(CONFIG_OPENVT) += openvt.o
CONSOLETOOLS-$(CONFIG_RESET) += reset.o
+CONSOLETOOLS-$(CONFIG_RESIZE) += resize.o
CONSOLETOOLS-$(CONFIG_SETKEYCODES) += setkeycodes.o
CONSOLETOOLS-$(CONFIG_SETLOGCONS) += setlogcons.o
Index: console-tools/resize.c
===================================================================
--- console-tools/resize.c (revision 0)
+++ console-tools/resize.c (revision 0)
@@ -0,0 +1,41 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * resize - set terminal width and height.
+ *
+ * Copyright 2006 Bernhard Fischer
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+/* no options, no getopt */
+#include "busybox.h"
+
+#define RESIZE_TIOS_TIMEOUT 100 /* in deciseconds */
+int resize_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv) {
+ /* save_cursor_pos 7
+ * scroll_whole_screen [r
+ * put_cursor_waaaay_off [$x;$yH
+ * get_cursor_pos [6n
+ * restore_cursor_pos 8
+ */
+ struct winsize w = {0,0,0,0};
+ int ret;
+ struct termios old, new;
+ tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */
+ new = old;
+ new.c_cflag |= (CLOCAL | CREAD);
+ new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+#if defined(RESIZE_TIOS_TIMEOUT) && (RESIZE_TIOS_TIMEOUT > 0)
+ new.c_cc[VMIN] = 0;
+ new.c_cc[VTIME] = RESIZE_TIOS_TIMEOUT;
+#endif
+ tcsetattr(STDOUT_FILENO, TCSANOW, &new);
+ printf("\0337\033[r\033[999;999H\033[6n");
+ scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col);
+ ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);
+ printf("\0338");
+ tcsetattr(STDOUT_FILENO, TCSANOW, &old);
+ if (00 && argc > 1)
+ printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;",
+ w.ws_col, w.ws_row);
+ return ret;
+}
Index: console-tools/Config.in
===================================================================
--- console-tools/Config.in (revision 16161)
+++ console-tools/Config.in (working copy)
@@ -58,6 +58,13 @@ config CONFIG_RESET
This program is used to reset the terminal screen, if it
gets messed up.
+config CONFIG_RESIZE
+ bool "resize"
+ default n
+ help
+ This program is used to (re)set the width and height of your current
+ terminal.
+
config CONFIG_SETCONSOLE
bool "setconsole"
default n
Index: include/libbb.h
===================================================================
--- include/libbb.h (revision 16161)
+++ include/libbb.h (working copy)
@@ -231,8 +231,9 @@ extern void trim(char *s);
extern char *skip_whitespace(const char *);
#ifndef BUILD_INDIVIDUAL
-extern struct BB_applet *find_applet_by_name(const char *name);
-void run_applet_by_name(const char *name, int argc, char **argv);
+extern struct BB_applet *find_applet_by_name(const char *name)
+ USE_FEATURE_SH_STANDALONE_SHELL(ATTRIBUTE_EXTERNALLY_VISIBLE);
+extern void run_applet_by_name(const char *name, int argc, char **argv);
#endif
/* dmalloc will redefine these to it's own implementation. It is safe
Index: include/usage.h
===================================================================
--- include/usage.h (revision 16163)
+++ include/usage.h (working copy)
@@ -2455,6 +2455,11 @@ USE_FEATURE_MDEV_CONFIG( \
#define reset_full_usage \
"Resets the screen."
+#define resize_trivial_usage \
+ ""
+#define resize_full_usage \
+ "Resizes the screen."
+
#define rm_trivial_usage \
"[OPTION]... FILE..."
#define rm_full_usage \
Index: include/applets.h
===================================================================
--- include/applets.h (revision 16161)
+++ include/applets.h (working copy)
@@ -226,6 +226,7 @@ USE_REALPATH(APPLET(realpath, _BB_DIR_US
USE_HALT(APPLET_ODDNAME(reboot, halt, _BB_DIR_SBIN, _BB_SUID_NEVER, reboot))
USE_RENICE(APPLET(renice, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_RESET(APPLET(reset, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
+USE_RESIZE(APPLET(resize, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_RM(APPLET(rm, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_RMDIR(APPLET(rmdir, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_NEVER))
More information about the busybox
mailing list