1 /*
2 DF-SHOW: An interactive directory/file browser written for Unix-like systems.
3 Based on the applications from the PC-DOS DF-EDIT suite by Larry Kroeker.
4 Copyright (C) 2018-2021 Robert Ian Hawdon
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #define _GNU_SOURCE
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <ncurses.h>
25 #include <string.h>
26 #include <wchar.h>
27 #include "colors.h"
28
29 extern int * pc;
30
wPrintLine(int line,int col,wchar_t * textString)31 void wPrintLine(int line, int col, wchar_t *textString){
32 int i;
33 move(line,col);
34 clrtoeol();
35 for ( i = 0; i < wcslen(textString) ; i++){
36 mvprintw(line, col + i, "%lc", textString[i]);
37 if ( (col + i) == COLS ){
38 break;
39 }
40 }
41 }
42
printLine(int line,int col,char * textString)43 void printLine(int line, int col, char *textString){
44 // Small wrapper to seemlessly forward calls to the wide char version
45 wchar_t *wTextString;
46 wTextString = malloc( sizeof ( wchar_t ) * (strlen(textString) + 1));
47 swprintf(wTextString, strlen(textString) + 1, L"%s", textString);
48 wPrintLine(line, col, wTextString);
49 free(wTextString);
50 }
51
52
topLineMessage(const char * message)53 void topLineMessage(const char *message){
54 move(0,0);
55 clrtoeol();
56 setColors(ERROR_PAIR);
57 mvprintw(0,0, "%s", message);
58 setColors(COMMAND_PAIR);
59 while(1)
60 {
61 *pc = getch();
62 switch(*pc)
63 {
64 case -1:
65 break;
66 default: // Where's the "any" key?
67 return;
68 break;
69 }
70 }
71 }
72
clear_workspace()73 void clear_workspace()
74 {
75 size_t line_count = 1;
76 for (line_count = 1; line_count < (LINES - 1);)
77 {
78 move (line_count,0);
79 clrtoeol();
80 line_count++;
81 }
82 }
83