From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] edit: replace %c for literal with literal directly
Date: Mon, 14 Oct 2019 22:04:07 +0200 [thread overview]
Message-ID: <20191014200408.17643-1-ahmad@a3f.at> (raw)
There's no need to use %c for ESC, when we can use the appropriate
escape sequence directly. Do this and shave off 60~ bytes on my
compressed THUMB-2 barebox.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
commands/edit.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/commands/edit.c b/commands/edit.c
index ba6a8c7cdd78..8668a8c0655c 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -55,7 +55,7 @@ static int scrcol = 0; /* the first column on screen */
static void pos(int x, int y)
{
- printf("%c[%d;%dH", 27, y + 2, x + 1);
+ printf("\x1b[%d;%dH", y + 2, x + 1);
}
static char *screenline(char *line, int *pos)
@@ -110,7 +110,7 @@ static void refresh_line(struct line *line, int ypos)
char *str = screenline(line->data, NULL) + scrcol;
pos(0, ypos);
str[screenwidth] = 0;
- printf("%s%c[K", str, 27);
+ printf("%s\x1b[K", str);
pos(cursx, cursy);
}
@@ -130,7 +130,7 @@ static void refresh(int full)
if (!full) {
if (smartscroll) {
if (scrline->next == lastscrline) {
- printf("%c[1T", 27);
+ printf("\x1b[1T");
refresh_line(scrline, 0);
pos(0, screenheight);
printf("%*s", screenwidth, "");
@@ -138,7 +138,7 @@ static void refresh(int full)
}
if (scrline->prev == lastscrline) {
- printf("%c[1S", 27);
+ printf("\x1b[1S");
for (i = 0; i < screenheight - 1; i++) {
l = l->next;
if (!l)
@@ -420,13 +420,13 @@ static int do_edit(int argc, char *argv[])
lastscrline = scrline;
lastscrcol = 0;
- printf("%c[2J", 27);
+ printf("\x1b[2J");
pos(0, -1);
- printf("%c[7m %-25s <ctrl-d>: Save and quit <ctrl-c>: quit %c[0m",
- 27, argv[1], 27);
- printf("%c[2;%dr", 27, screenheight);
+ printf("\x1b[7m %-25s <ctrl-d>: Save and quit <ctrl-c>: quit \x1b[0m",
+ argv[1]);
+ printf("\x1b[2;%dr", screenheight);
screenheight--; /* status line */
@@ -554,7 +554,7 @@ static int do_edit(int argc, char *argv[])
}
out:
free_buffer();
- printf("%c[2J%c[r", 27, 27);
+ printf("\x1b[2J\x1b[r");
printf("\n");
return ret;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2019-10-14 20:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 20:04 Ahmad Fatoum [this message]
2019-10-14 20:04 ` [PATCH 2/2] edit: add vi alias with vi-style bindings Ahmad Fatoum
2019-10-18 12:19 ` [PATCH 1/2] edit: replace %c for literal with literal directly Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191014200408.17643-1-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox