@@ 617,22 617,34 @@ static void print_usage(int fd, const char* prog)
dprintf(fd, " -H don't close the window when stdin closes\n");
dprintf(fd, " -A ACTION run ACTION (like system(3) does) when enter, space or mouse buttons are pressed ($0 is bound to the relevant button)\n");
dprintf(fd, " -p FILE write pid to FILE\n");
+ dprintf(fd, " -s SIZE use default font of size SIZE\n");
dprintf(fd, " -h print this message\n");
}
+static const char* default_font(unsigned int size)
+{
+ static char buf[64];
+
+ int r = snprintf(LIT(buf), "sans:pixelsize=%u", size);
+ CHECK(r, "snprintf");
+ CHECK_IF(r >= LENGTH(buf), "truncated");
+
+ return buf;
+}
+
static void parse_options(struct options* o, int argc, char* argv[])
{
o->name = argv[0];
o->anchor = ANCHOR_FREE;
o->sep = '\n';
o->initial_buffer_size = 128;
- o->font = "sans:pixelsize=34";
+ o->font = default_font(34);
o->hang = 0;
o->action = NULL;
o->pid_file = NULL;
int res;
- while((res = getopt(argc, argv, "a:0t:f:HA:p:h")) != -1) {
+ while((res = getopt(argc, argv, "a:0t:f:HA:p:s:h")) != -1) {
switch(res) {
case 'a':
if(strcmp(optarg, "N") == 0) {
@@ 679,6 691,15 @@ static void parse_options(struct options* o, int argc, char* argv[])
o->pid_file = strdup(optarg);
CHECK_MALLOC(o->pid_file);
break;
+ case 's': {
+ unsigned int s;
+ if(sscanf(optarg, "%u", &s) != 1) {
+ dprintf(2, "unable to parse font size: %s\n", optarg);
+ exit(1);
+ }
+ o->font = default_font(s);
+ break;
+ }
case 'h':
default:
print_usage(res == 'h' ? 1 : 2, argv[0]);