| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "sysdep.h" |
| 10 |
|
| 11 |
|
| 12 |
#ifdef HAVE_TERMIOS |
| 13 |
|
| 14 |
#ifdef __linux__ |
| 15 |
#include <sys/ioctl.h> |
| 16 |
#include <asm/ioctls.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
#ifdef __FreeBSD__ |
| 20 |
#include <sys/ioctl.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
#endif |
| 24 |
|
| 25 |
#ifdef HAVE_GLK |
| 26 |
#include "glkio.h" |
| 27 |
#endif |
| 28 |
|
| 29 |
|
| 30 |
#include "memory.h" |
| 31 |
#include "output.h" |
| 32 |
#include "options.h" |
| 33 |
#include "instance.h" |
| 34 |
#include "current.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
bool onStatusLine = false; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#ifdef __windows__ |
| 43 |
|
| 44 |
#include <windows.h> |
| 45 |
|
| 46 |
HWND getConsoleHandle(void) { |
| 47 |
char oldTitle[1000]; |
| 48 |
char newTitle[1000]; |
| 49 |
HWND handle; |
| 50 |
|
| 51 |
GetConsoleTitle(oldTitle, 1000); |
| 52 |
|
| 53 |
wsprintf(newTitle, "Arun console%d-%d", GetTickCount(), GetCurrentProcessId()); |
| 54 |
SetConsoleTitle(newTitle); |
| 55 |
Sleep(50); |
| 56 |
handle = FindWindow(NULL, newTitle); |
| 57 |
SetConsoleTitle(oldTitle); |
| 58 |
return handle; |
| 59 |
} |
| 60 |
#endif |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
void getPageSize(void) |
| 72 |
{ |
| 73 |
#ifdef HAVE_GLK |
| 74 |
pageLength = 0; |
| 75 |
pageWidth = 0; |
| 76 |
|
| 77 |
#else |
| 78 |
#ifdef HAVE_TERMIOS |
| 79 |
|
| 80 |
#include <sys/termios.h> |
| 81 |
|
| 82 |
#ifdef __linux__ |
| 83 |
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW; |
| 84 |
#else |
| 85 |
extern int ioctl(); |
| 86 |
#endif |
| 87 |
struct winsize win; |
| 88 |
int ecode; |
| 89 |
|
| 90 |
ecode = ioctl(1, TIOCGWINSZ, &win); |
| 91 |
|
| 92 |
if (ecode != 0 || win.ws_row == 0) |
| 93 |
pageLength = header->pageLength; |
| 94 |
else |
| 95 |
pageLength = win.ws_row; |
| 96 |
|
| 97 |
if (ecode != 0 || win.ws_col == 0) |
| 98 |
pageWidth = header->pageWidth; |
| 99 |
else |
| 100 |
pageWidth = win.ws_col; |
| 101 |
|
| 102 |
#else |
| 103 |
|
| 104 |
pageLength = header->pageLength; |
| 105 |
pageWidth = header->pageWidth; |
| 106 |
|
| 107 |
#endif |
| 108 |
#endif |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
void statusline(void) |
| 113 |
{ |
| 114 |
#ifdef HAVE_GLK |
| 115 |
glui32 glkWidth; |
| 116 |
char line[100]; |
| 117 |
int pcol = col; |
| 118 |
|
| 119 |
if (!statusLineOption) return; |
| 120 |
if (glkStatusWin == NULL) |
| 121 |
return; |
| 122 |
|
| 123 |
glk_set_window(glkStatusWin); |
| 124 |
glk_window_clear(glkStatusWin); |
| 125 |
glk_window_get_size(glkStatusWin, &glkWidth, NULL); |
| 126 |
|
| 127 |
#ifdef HAVE_GARGLK |
| 128 |
int i; |
| 129 |
glk_set_style(style_User1); |
| 130 |
for (i = 0; i < glkWidth; i++) |
| 131 |
glk_put_char(' '); |
| 132 |
#endif |
| 133 |
|
| 134 |
onStatusLine = true; |
| 135 |
col = 1; |
| 136 |
glk_window_move_cursor(glkStatusWin, 1, 0); |
| 137 |
sayInstance(where(HERO, true)); |
| 138 |
|
| 139 |
|
| 140 |
if (header->maximumScore > 0) |
| 141 |
sprintf(line, "Score %d(%d)/%d moves", current.score, (int)header->maximumScore, current.tick); |
| 142 |
else |
| 143 |
sprintf(line, "%d moves", current.tick); |
| 144 |
glk_window_move_cursor(glkStatusWin, glkWidth-strlen(line)-1, 0); |
| 145 |
glk_put_string(line); |
| 146 |
needSpace = false; |
| 147 |
|
| 148 |
col = pcol; |
| 149 |
onStatusLine = false; |
| 150 |
|
| 151 |
glk_set_window(glkMainWin); |
| 152 |
#else |
| 153 |
#ifdef HAVE_ANSI_CONTROL |
| 154 |
char line[100]; |
| 155 |
int i; |
| 156 |
int pcol = col; |
| 157 |
|
| 158 |
if (!statusLineOption) return; |
| 159 |
|
| 160 |
printf("\x1b[1;1H"); |
| 161 |
printf("\x1b[7m"); |
| 162 |
|
| 163 |
onStatusLine = true; |
| 164 |
col = 1; |
| 165 |
sayInstance(where(HERO, false)); |
| 166 |
|
| 167 |
if (header->maximumScore > 0) |
| 168 |
sprintf(line, "Score %d(%d)/%d moves", current.score, header->maximumScore, current.tick); |
| 169 |
else |
| 170 |
sprintf(line, "%ld moves", (long)current.tick); |
| 171 |
for (i=0; i < pageWidth - col - strlen(line); i++) putchar(' '); |
| 172 |
printf(line); |
| 173 |
printf("\x1b[m"); |
| 174 |
printf("\x1b[%d;1H", pageLength); |
| 175 |
|
| 176 |
needSpace = false; |
| 177 |
capitalize = true; |
| 178 |
|
| 179 |
onStatusLine = false; |
| 180 |
col = pcol; |
| 181 |
#endif |
| 182 |
#endif |
| 183 |
} |