File: window.c

package info (click to toggle)
aoeui 1.4-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 440 kB
  • ctags: 574
  • sloc: ansic: 6,005; makefile: 76; sh: 11
file content (773 lines) | stat: -rw-r--r-- 20,117 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/* Copyright 2007, 2008 Peter Klausler.  See COPYING for license. */
#include "all.h"

/*
 *	A "window" is a presentation of a view on part or all of
 *	the display surface.  One window is active, meaning that
 *	it directs keyboard input to its view's command handler.
 */

struct window {
	struct view *view;
	locus_t start;
	unsigned row, column;
	unsigned rows, columns;
	unsigned cursor_row, cursor_column;
	rgba_t fgrgba, bgrgba;
	unsigned last_dirties;
	position_t last_cursor, last_mark;
	rgba_t last_fgrgba, last_bgrgba;
	struct window *next;
};

static struct window *window_list;
static struct window *active_window;
static struct display *display;
static unsigned display_rows, display_columns;

static void title(struct window *window)
{
	char buff[128];
	if (window != active_window)
		return;
	if (!window) {
		display_title(display, NULL);
		return;
	}
	snprintf(buff, sizeof buff, "%s%s",
		 window->view->name,
		 window->view->text->flags & TEXT_CREATED ? "(new)" :
		 window->view->text->flags & TEXT_RDONLY ? "(read-only)" :
		 window->view->text->preserved !=
		    window->view->text->dirties ? "(unsaved)" : "");
	display_title(display, buff);
}

static struct window *activate(struct window *window)
{
	active_window = window;
	title(window);
	return window;
}

static struct window *window_create(struct view *view, struct view *after)
{
	struct window *window = view->window;

	if (!window) {
		window = allocate0(sizeof *window);
		window->view = view;
		view->window = window;
		window->start = locus_create(view, UNSET);
		if (after && after->window) {
			window->next = after->window->next;
			after->window->next = window;
		} else {
			window->next = window_list;
			window_list = window;
		}
	} else
		window->row = window->column = 0;
	window->rows = display_rows;
	window->columns = display_columns;
	window->last_dirties = ~0;
	return window;
}

static Boolean_t stacked(struct window *up, struct window *down)
{
	return	up && down &&
		up->column == down->column &&
		up->columns == down->columns &&
		up->row + up->rows == down->row;
}

static Boolean_t beside(struct window *left, struct window *right)
{
	return	left && right &&
		left->row == right->row &&
		left->rows == right->rows &&
		left->column + left->columns == right->column;
}

static Boolean_t adjacent(struct window *x, struct window *y)
{
	if (x->column + x->columns < y->column ||
	    y->column + y->columns < x->column ||
	    x->row + x->rows < y->row ||
	    y->row + y->rows < x->row)
		return FALSE;
	if (y->column != x->column + x->columns &&
	    x->column != y->column + y->columns)
		return TRUE;
	return y->row < x->row + x->rows &&
	       x->row < y->row + y->rows;
}

static Boolean_t window_expand_next(struct window *window)
{
	struct window *next = window->next;
	if (!next)
		return FALSE;
	if (stacked(window, next)) {
		next->row = window->row;
		next->rows += window->rows;
		return TRUE;
	}
	if (beside(window, next)) {
		next->column = window->column;
		next->columns += window->columns;
		return TRUE;
	}
	return FALSE;
}

void window_destroy(struct window *window)
{
	struct window *previous = NULL, *wp;

	if (!window)
		return;
	for (wp = window_list; wp != window; previous = wp, wp = wp->next)
		if (wp == window)
			break;
	if (!wp)
		;
	else if (previous) {
		struct window *next = previous->next = window->next;
		if (stacked(previous, window) &&
		    (!stacked(window, next) ||
		     previous->rows <= next->rows))
			previous->rows += window->rows;
		else if (beside(previous, window) &&
			 (!beside(window, next) ||
			  previous->columns <= next->columns))
			previous->columns += window->columns;
		else if (!window_expand_next(window))
			window_raise(previous->view);
	} else if ((window_list = window->next) &&
		   !window_expand_next(window))
		window_raise(window_list->view);

	if (window->view) {
		locus_destroy(window->view, window->start);
		window->view->window = NULL;
	}
	if (window == active_window) {
		wp = window_list;
		if (previous) {
			wp = previous;
			if (wp->next)
				wp = wp->next;
		}
		activate(wp);
	}
	RELEASE(window);
}

struct window *window_raise(struct view *view)
{
	if (!display)
		display = display_init();
	display_get_geometry(display, &display_rows, &display_columns);
	display_erase(display, 0, 0, display_rows, display_columns,
		      DEFAULT_FGRGBA, DEFAULT_BGRGBA);
	while (window_list && window_list->view != view)
		window_destroy(window_list);
	while (window_list && window_list->next)
		window_destroy(window_list->next);
	return activate(window_create(view, NULL));
}

struct window *window_activate(struct view *view)
{
	if (view->window)
		return activate(view->window);
	return window_raise(view);
}

struct window *window_after(struct view *before, struct view *view,
			    int vertical)
{
	struct window *window, *old;

	if (view->window)
		return view->window;
	if (!before ||
	    !(old = before->window) ||
	    old->rows < 4 ||
	    old->columns < 16)
		return window_raise(view);
	window = window_create(view, before);
	if (vertical < 0)
		vertical = old->columns > 120;
	if (vertical) {
		window->row = old->row;
		window->rows = old->rows;
		window->column = old->column +
			(old->columns -=
			 (window->columns =
			  old->columns >> 1));
	} else {
		window->column = old->column;
		window->columns = old->columns;
		window->row = old->row +
			(old->rows -=
			 (window->rows =
			  old->rows >> 1));
	}
	return activate(window);
}

struct window *window_below(struct view *above, struct view *view,
			    unsigned rows)
{
	struct window *window, *old;
	if (view->window)
		return view->window;
	if (!above && active_window)
		above = active_window->view;
	if (!above || !(old = above->window) || old->rows < rows*2)
		return window_raise(view);
	window = window_create(view, above);
	window->column = old->column;
	window->columns = old->columns;
	window->row = old->row + (old->rows -= (window->rows = rows));
	return window;
}

struct window *window_replace(struct view *old, struct view *new)
{
	struct window *window = old->window;

	if (!new)
		return NULL;
	if (new->window)
		return new->window;
	if (!old || !window)
		return window_raise(new);
	window->view = new;
	old->window = NULL;
	locus_destroy(old, window->start);
	window->start = locus_create(new, locus_get(new, CURSOR)+1);
	return activate(new->window = window);
}

struct view *window_current_view(void)
{
	if (!active_window) {
		if (!text_list)
			view_help();
		window_raise(text_list->views);
	}
	return active_window->view;
}

void windows_end(void)
{
	while (window_list)
		window_destroy(window_list);
	if (display) {
		display_end(display);
		display = NULL;
	}
}

static unsigned count_rows(struct window *window, position_t start,
			   position_t end)
{
	unsigned rows = 0, bytes;

	for (rows = 0; start < end; rows++, start += bytes)
		if (!(bytes = find_row_bytes(window->view, start, 0,
					     window->columns)))
			break;
	return rows;
}

static position_t find_row_start(struct window *window, position_t position,
				 position_t start)
{
	size_t bytes;
	if (position && position >= window->view->bytes)
		position--;
	while ((bytes = find_row_bytes(window->view, start, 0, window->columns))) {
		if (start + bytes > position)
			break;
		start += bytes;
	}
	return start;
}

static void new_start(struct view *view, position_t start)
{
	locus_set(view, view->window->start, start ? start-1 : UNSET);
	view->window->last_dirties = ~0;
}

static position_t screen_start(struct view *view)
{
	position_t start = locus_get(view, view->window->start);
	if (start++ == UNSET)
		start = 0;
	return start;
}

static position_t focus(struct window *window)
{
	struct view *view = window->view;
	position_t cursor = locus_get(view, CURSOR);
	position_t cursorrow = find_row_start(window, cursor,
					      find_line_start(view, cursor));
	position_t start = screen_start(view);
	position_t end, at;
	unsigned above, below;
	size_t bytes;

	start = find_row_start(window, start,
			       find_line_start(view, start));
	if (cursorrow >= start &&
	    (above = count_rows(window, start, cursorrow)) < window->rows) {
		for (below = 1, at = cursorrow;
		     above + below < window->rows;
		     below++, at += bytes)
			if (!(bytes = find_row_bytes(view, at, 0, window->columns)))
				break;
		if (above + below == window->rows || !start)
			goto done;
	}

	for (start = cursorrow, above = 0;
	     (end = start) && above < window->rows >> 1;
	     above += count_rows(window, start, end))
		start = find_line_start(view, start-1);
	for (; above >= window->rows >> 1; above--)
		start += find_row_bytes(view, start, 0, window->columns);

	for (below = 1, at = cursorrow;
	     above + below < window->rows;
	     below++, at += bytes)
		if (!(bytes = find_row_bytes(view, at, 0, window->columns)))
			break;
	for (; (end = start) && above + below < window->rows;
	     above += count_rows(window, start, end))
		start = find_line_start(view, start-1);
	for (; above + below > window->rows; above--)
		start += find_row_bytes(view, start, 0, window->columns);

done:	window->cursor_column = find_column(&above, view, cursorrow,
					    cursor, 0);
	window->cursor_row = above;
	new_start(view, start);
	return start;
}

static Boolean_t lame_space(struct view *view, position_t start,
			    unsigned next_tab)
{
	unsigned distance = 0;
	position_t offset = start;
	Unicode_t ch;
	if (view->shell_std_in >= 0 || view->text->flags & TEXT_EDITOR)
		return FALSE;
	do {
		distance++;
		ch = view_char(view, offset, &offset);
		if (!IS_UNICODE(ch) || ch == '\n' || ch == '\t')
			return TRUE;
	} while (ch == ' ');
	return distance > next_tab &&
	       !(view->text->flags & TEXT_NO_TABS) &&
	       (next_tab ||
		view_char_prior(view, start-1, NULL) == ' ');
}

static Boolean_t lame_tab(struct view *view, position_t offset)
{
	Unicode_t ch;
	if (view->shell_std_in >= 0 || view->text->flags & TEXT_EDITOR)
		return FALSE;
	if (view->text->flags & TEXT_NO_TABS)
		return TRUE;
	for (;
	     IS_UNICODE(ch = view_char(view, offset, &offset)) &&
	     ch != '\n'; )
		if (ch != ' ' && ch != '\t')
			return FALSE;
	return TRUE;
}

static unsigned paintch(struct window *window, Unicode_t ch, unsigned row,
			unsigned column,
			position_t at, position_t cursor, position_t mark,
			unsigned *brackets, rgba_t fgrgba)
{
	rgba_t bgrgba = window->bgrgba;
	unsigned tabstop = window->view->text->tabstop;
	const char *brack = window->view->text->brackets;

	if (ch == '\n')
		return column;

	if (mark != UNSET &&
	    (at >= cursor && at < mark ||
	     at >= mark && at < cursor)) {
		bgrgba = 0x00ffff00;
		fgrgba = 0xff000000;
	} else if (at == cursor) {
		if (window->view->text->flags & TEXT_RDONLY)
			fgrgba = 0xff000000;
		else if (at == mark)
			fgrgba = 0xff00ff00;
		else if (text_is_dirty(window->view->text))
			fgrgba = 0x00ff0000;
	}

	if (ch == '\t') {
		rgba_t bg = lame_tab(window->view, at+1) ? 0xff00ff00 : bgrgba;
		do {
			display_put(display, window->row + row,
				    window->column + column++, ' ', fgrgba, bg);
			bg = bgrgba;
		} while (column % tabstop);
		return column;
	}

	if (ch < ' ' || ch == 0x7f || IS_FOLDED(ch)) {
		bgrgba = 0xff000000;
		fgrgba = 0xffffff00;
		display_put(display, window->row + row, window->column + column++,
			    IS_FOLDED(ch) ? '<' : '^', fgrgba, bgrgba);
		if (IS_FOLDED(ch))
			ch = '>';
		else if (ch == 0x7f)
			ch = '?';
		else
			ch += '@';
	} else if (ch == ' ') {
		if (bgrgba == window->bgrgba &&
		   lame_space(window->view, at + 1,
			      tabstop-1 - column % tabstop))
			bgrgba = 0xff00ff00;
	} else if (!IS_UNICODE(ch))
		ch = ' ', bgrgba = 0xff00ff00;
	else if (brack)
		for (; *brack; brack += 2)
			if (ch == brack[0] && (*brackets)++ & 1 ||
			    ch == brack[1] && --*brackets & 1) {
				fgrgba = 0x0000ff00;
				break;
			}

	display_put(display, window->row + row, window->column + column++,
		    ch, fgrgba, bgrgba);
	return column;
}

static Boolean_t needs_repainting(struct window *window)
{
	struct view *view = window->view;
	position_t cursor = locus_get(view, CURSOR);
	position_t mark = locus_get(view, MARK);

	if (mark == UNSET)
		mark = cursor;
	return	view->text->dirties != window->last_dirties ||
		window->last_fgrgba != window->fgrgba ||
		window->last_bgrgba != window->bgrgba ||
		window->last_cursor != cursor ||
		window->last_mark != mark;
}

static void repainted(struct window *window, position_t cursor, position_t mark)
{
	window->last_dirties = window->view->text->dirties;
	window->last_fgrgba = window->fgrgba;
	window->last_bgrgba = window->bgrgba;
	window->last_cursor = cursor;
	window->last_mark = mark;
}

static void paint(struct window *window)
{
	position_t at, next;
	unsigned row, column;
	struct view *view = window->view;
	position_t cursor = locus_get(view, CURSOR);
	position_t mark = locus_get(view, MARK);
	unsigned brackets = 1;

	title(window);

	at = focus(window);
	for (row = 0; row < window->rows; row++) {

		position_t limit = at + find_row_bytes(view, at, 0,
						       window->columns);
		rgba_t fgrgba = window->fgrgba;
		Boolean_t keywords = view->text->keywords &&
				     (fgrgba == DEFAULT_FGRGBA ||
				      !fgrgba);
		Boolean_t look_for_keyword = keywords;

		for (column = 0; at < limit; at = next) {
			Unicode_t ch = view_char(view, at, &next);
			if (!is_idch(ch) && ch != '#') {
				fgrgba = window->fgrgba;
				look_for_keyword = keywords;
			} else if (look_for_keyword && is_keyword(view, at))
				fgrgba = 0x0000ff00;
			else
				look_for_keyword = FALSE;
			column = paintch(window, ch, row, column, at,
					 cursor, mark, &brackets,
					 fgrgba);
		}

		display_erase(display, window->row + row,
			      window->column + column, 1,
			      window->columns - column,
			      window->fgrgba, window->bgrgba);
	}

	repainted(window, cursor, mark);
}

void window_hint_deleting(struct window *window, position_t offset, size_t bytes)
{
	struct view *view = window->view;
	position_t at = screen_start(view);
	unsigned row = 0, column;
	unsigned lines = 0, end_column;

	if (focus(window) != at || offset + bytes <= at)
		return;
	if (offset < at) {
		bytes -= at - offset;
		offset = at;
	}
	if (!bytes || view_char(view, offset, NULL) >= FOLD_START)
		return;
	column = find_column(&row, view, at, offset, 0);
	if (row >= window->rows)
		return;
	end_column = find_column(&lines, view, offset,
				 offset + bytes, column);
	if (!lines) {
		unsigned old = find_row_bytes(view, offset,
					      column, window->columns);
		unsigned new = find_row_bytes(view, offset + bytes,
					      end_column, window->columns);
		if (new + bytes == old) {
			display_delete_chars(display, window->row + row,
					     window->column + column,
					     end_column - column,
					     window->columns, window->fgrgba,
					     window->bgrgba);
			return;
		}
		lines++;
	}
	if (row + lines >= window->rows) {
		lines = window->rows - row;
		end_column = 0;
	}
	display_delete_lines(display, window->row + row, window->column,
			     lines, window->rows, window->columns,
			     window->fgrgba, window->bgrgba);
}

void window_hint_inserted(struct window *window, position_t offset, size_t bytes)
{
	struct view *view = window->view;
	position_t at = screen_start(view);
	position_t column, end_column;
	unsigned row = 0, lines = 0;

	if (focus(window) != at || offset + bytes <= at)
		return;
	if (offset < at) {
		bytes -= at - offset;
		offset = at;
	}
	if (!bytes || view_char(view, offset, NULL) >= FOLD_START)
		return;
	column = find_column(&row, view, at, offset, 0);
	if (row >= window->rows)
		return;
	end_column = find_column(&lines, view, offset,
				 offset + bytes, column);
	if (!lines) {
		size_t old = find_row_bytes(view, offset + bytes,
					    end_column, window->columns);
		size_t new = find_row_bytes(view, offset,
					    column, window->columns);
		if (new == old + bytes) {
			display_insert_spaces(display, window->row + row,
					      window->column + column,
					      end_column - column,
					      window->columns, window->fgrgba,
					      window->bgrgba);
			return;
		}
		lines++;
	}
	if (row + lines >= window->rows) {
		lines = window->rows - row;
		end_column = 0;
	}
	display_insert_lines(display, window->row + row, window->column,
			     lines, window->rows, window->columns,
			     window->fgrgba, window->bgrgba);
}

void window_next(struct view *view)
{
	if (view && view->window)
		activate(view->window->next ? view->window->next : window_list);
}

struct window *window_recenter(struct view *view)
{
	struct window *window = view->window;
	position_t cursor = locus_get(view, CURSOR);
	position_t start, end;
	int row;

	if (!window)
		window = window_raise(view);
	start = find_row_start(window, cursor, find_line_start(view, cursor));
	for (row = 0;
	     (end = start) && row < window->rows >> 1;
	     row += count_rows(window, start, end))
		start = find_line_start(view, start-1);
	while(row-- > window->rows >> 1)
		start += find_row_bytes(view, start, 0, window->columns);
	new_start(view, start);
	return window;
}

#define OVERLAP 1
void window_page_up(struct view *view)
{
	struct window *window = view->window;
	position_t start = screen_start(view);
	position_t end;
	int row;
	size_t bytes;

	if (start) {
		for (row = 0;
		     (end = start) && row + OVERLAP < window->rows;
		     row += count_rows(window, start, end))
			start = find_line_start(view, start-1);
		while (row-- + OVERLAP > window->rows)
			start += find_row_bytes(view, start, 0, window->columns);
		new_start(view, start);
		for (row = 0; row < window->rows-1; row++, start += bytes)
			if (!(bytes = find_row_bytes(view, start, 0,
						     window->columns)))
				break;
		display_insert_lines(display, window->row, window->column,
				     1, window->rows, window->columns,
				     window->fgrgba, window->bgrgba);
	}
	locus_set(view, CURSOR, start);
}

void window_page_down(struct view *view)
{
	struct window *window = view->window;
	position_t start = screen_start(view);
	int row;
	size_t bytes;

	for (row = 0; row + OVERLAP < window->rows; row++, start += bytes)
		if (!(bytes = find_row_bytes(view, start, 0, window->columns)))
			break;
	display_delete_lines(display, window->row, window->column, 1,
			     window->rows, window->columns,
			     window->fgrgba, window->bgrgba);
	new_start(view, start);
	locus_set(view, CURSOR, start);
}

void window_beep(struct view *view)
{
	if (display)
		display_beep(display);
	else
		fputc('\a', stderr);
}

static void window_colors(void)
{
	int j;
	struct window *window, *w;

	static rgba_t colors[][2] = {
		{ DEFAULT_FGRGBA, DEFAULT_BGRGBA },
		{ 0x00000000, 0x7f7f7f00 },
		{ 0x00000000, 0xffffff00 },
		{ 0x0000ff00, 0xffff0000 },
		{ 0x0000ff00, 0x7f7f0000 },
		{ 0x00ff0000, 0xff00ff00 },
		{ 0x00ff0000, 0x7f007f00 },
		{ 0xff000000, 0x007f7f00 },
		{ 0xff000000, 0x00ffff00 },
		{ }
	};

	for (window = window_list; window; window = window->next)
		window->bgrgba = 0;
	j = active_window != window_list || active_window->next;
	active_window->fgrgba = colors[j][0];
	active_window->bgrgba = colors[j][1];
	for (window = window_list; window; window = window->next) {
		if (window->bgrgba)
			continue;
		for (j = 1; colors[j][1]; j++) {
			for (w = window_list; w; w = w->next)
				if (w != window &&
				    w->bgrgba == colors[j][1] &&
				    adjacent(window, w))
					break;
			if (!w)
				break;
		}
		window->fgrgba = colors[j][0];
		window->bgrgba = colors[j][1];
	}
}

static void repaint(void)
{
	struct window *window;

	window_colors();
	for (window = window_list; window; window = window->next)
		if (needs_repainting(window))
			paint(window);
	display_cursor(display,
		       active_window->row + active_window->cursor_row,
		       active_window->column + active_window->cursor_column);
}

Unicode_t window_getch(void)
{
	Boolean_t block = FALSE;
	for (;;) {
		Unicode_t ch = display_getch(display, block);
		if (ch == ERROR_CHANGED)
			window_raise(window_current_view());
		else if (ch != ERROR_EMPTY)
			return ch;
		repaint();
		block = TRUE;
	}
}

unsigned window_columns(struct window *window)
{
	return window ? window->columns : 80;
}