Skip to content

Commit ef1851a

Browse files
committed
Check terminal size.
Sprite 1.7
1 parent eb4d5f8 commit ef1851a

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ You can use it to create and share pixel art.
66
By default, sprite sets up a 16x16 pixel canvas.
77
If you'd like the larger 32x32 pixel canvas,
88
start sprite with the -e flag.
9-
It is the responsibility of the user to ensure the terminal is properly sized.
9+
If your terminal is not large enough to fit the 32x32 canvas,
10+
it will use the 16x16 canvas instead.
1011

1112
Requirements
1213
------------

sprite.1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ You can use it to create and share pixel art.
3333
The options are as follows:
3434
.Bl -tag -width Ds
3535
.It Fl e
36-
Use an extended canvas of 32x32 pixels instead of the default 16x16 pixels.
36+
Use an extended canvas of 32x32 pixels instead of the default 16x16 pixels,
37+
if the terminal is large enough to support the larger canvas.
3738
.El
3839
.Sh AUTHORS
3940
.Nm
4041
was written by
4142
.An Brian Callahan Aq Mt bcallah@openbsd.org .
4243
.Sh CAVEATS
43-
It is the responsibility of the user to ensure the terminal is properly
44-
sized.
45-
.Pp
4644
Console aspect ratio may not match user expectations.
4745
PNG export creates standard square pixels.

sprite.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ color_panel(void)
169169
static void
170170
scrinit(void)
171171
{
172-
int i;
172+
int i, x, y;
173173

174174
if (has_colors() == FALSE) {
175175
endwin();
@@ -179,6 +179,14 @@ scrinit(void)
179179
start_color();
180180
init_colors();
181181

182+
getmaxyx(stdscr, y, x);
183+
if (y < 39 || x < 90)
184+
extended = 0;
185+
if (y < 23 || x < 74) {
186+
endwin();
187+
errx(1, "terminal too small!");
188+
}
189+
182190
move(3, 31);
183191

184192
addch(ACS_ULCORNER);
@@ -392,7 +400,7 @@ file_save(int y, int x)
392400
noecho();
393401

394402
if ((fp = fopen(buf, "w+")) == NULL) {
395-
move(21, 31);
403+
move(21 + (extended ? 16 : 0), 31);
396404
printw("Error: could not open %s for writing", buf);
397405
goto out;
398406
}

0 commit comments

Comments
 (0)