Skip to content

Commit

Permalink
Find and Save as buttons, fix minor code indent, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
samtupy committed Aug 13, 2023
1 parent 91ffe9c commit a1bfa76
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ While this little program I've made by no means improves NVDA's scrolling functi
## Usage
It really couldn't be more simple, just drop show.exe somewhere on your path (anywhere from c:\windows to c:\users\%username% so long as it's part of the path environment variable), then in the command line, you can test by running "dir c:\windows\system32|show" and see how you can instantly review every bit of that massive directory listing where as before you could only view the last 30 lines of it without extra hastle! Of course you can pipe anything to show.exe that you could pipe to the clip command. Easily reviewing git logs in a seekable manner is another great use for this, for example.

The resulting dialog is very simple, containing only a read only edit box with command output and a close button. Though there is no menu bar or anything to make this visible somewhere, you can indeed press ctrl+f or f3 to open a standard find dialog. As with most applications, f3 and shift+f3 remember the last search term so that you can jump between occurances of text easily. The finding here doesn't wrap around yet, I'll likely get around to that soon.
The resulting dialog is very simple, containing a read only edit box with command output, a find button, and a save as button. You can also press ctrl+f or f3 in the text field to open the standard find dialog. As with most applications, f3 and shift+f3 remember the last search term so that you can jump between occurances of text easily. The finding here doesn't wrap around yet, I'll likely get around to that soon. The save as feature can also be accessed by pressing control+s in the text field. The aplication always saves files encoded in UTF8.

The only other feature is that you can press ctrl+s to save the output to a UTF8 encoded text file should you desire after reviewing it, because the entire point of this program is to hopefully make notepad NOT be a part of just basically using your terminal!
You can exit the application by pressing either escape or alt+f4. You can also press ctrl+c in the terminal window you launched the application from by piping another process to it.

It's not any more complicated than that!

Expand Down
17 changes: 12 additions & 5 deletions show.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
BOOL CALLBACK textbox_callback(HWND hwnd, UINT message, WPARAM wp, LPARAM lp);
LRESULT CALLBACK edit_control_callback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
#ifdef TXT_NOBEEPS
void disable_richedit_beeps(HMODULE richedit_module, HWND richedit_control);
void disable_richedit_beeps(HMODULE richedit_module, HWND richedit_control);
#endif
void find(HWND hwnd, int dir);
void save(HWND hwnd);
// Globals required for the find dialog.
WNDPROC original_edit_control_callback = NULL; // We need to subclass the textbox since the main dialog isn't receiving WM_KEYDOWN for some reason.
wchar_t text_to_search[256];
Expand Down Expand Up @@ -74,17 +76,17 @@ int main() {
character_size = 0;
for(i = 1; i <= 4; i ++) { // One of these 4 bytes will tell us the size of the character we're dealing with.
unsigned char c;
c = output_tmp[console_bytes_read - i];
c = output_tmp[console_bytes_read - i];
if(c < 192) continue; // another continuation char.
for(character_size = 2; character_size <=4; character_size ++) {
if((c & (1 << (7 - character_size))) == 0) break;
}
if(character_size) break;
if(character_size) break;
}
if(character_size - i > 0) {
ReadFile(cin, output_tmp + console_bytes_read, character_size - i, &bytes_read_tmp, NULL);
console_bytes_read += bytes_read_tmp;
}
console_bytes_read += bytes_read_tmp;
}
} // fwiw, that UTF8 correction thoroughly sucked.
text_transcode_result = MultiByteToWideChar(text_codepage != -1? text_codepage : 1252, text_codepage != -1? MB_ERR_INVALID_CHARS : 0, output_tmp, console_bytes_read, output + cursor, console_bytes_read); // Codepage can end up being unquestioningly windows1252 if transcoding attempts below fail, but we don't want to re-check encodings every text block.
if(!text_transcode_result) {
Expand Down Expand Up @@ -152,6 +154,10 @@ BOOL CALLBACK textbox_callback(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) {
event = HIWORD(wp);
if(control == IDCANCEL && event == BN_CLICKED)
DestroyWindow(hwnd);
else if(control == IDC_FIND && event == BN_CLICKED)
find(GetDlgItem(hwnd, IDC_TEXT), 0);
else if(control == IDC_SAVE && event == BN_CLICKED)
save(GetDlgItem(hwnd, IDC_TEXT));
return TRUE;
}
case WM_DESTROY: {
Expand Down Expand Up @@ -199,6 +205,7 @@ void find(HWND hwnd, int dir) {
SendMessage(hwnd, EM_FINDTEXTEX, (dir > 0? FR_DOWN : 0) | (find_dlg_flags & FR_MATCHCASE? FR_MATCHCASE : 0) | (find_dlg_flags & FR_WHOLEWORD ? FR_WHOLEWORD : 0), (LPARAM)&ft);
if(ft.chrgText.cpMin >= 0) {
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText);
SetFocus(hwnd); // Encase find dialog was activated through button instead of shortcut.
SendMessage(find_dlg, WM_CLOSE, 0, 0);
} else MessageBox((find_dlg? find_dlg : hwnd), L"nothing found for the given search", L"error", MB_ICONERROR);
}
Expand Down
6 changes: 4 additions & 2 deletions textbox.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#define IDC_STATIC (-1)
#endif
#define textbox 111
#define IDC_TEXT 1001
#define IDL_TEXT 1011
#define IDL_TEXT 1002
#define IDC_FIND 1003
#define IDC_SAVE 1004
5 changes: 3 additions & 2 deletions textbox.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include <windows.h>
#include "textbox.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
textbox DIALOG 0, 0, 145, 67
textbox DIALOG 0, 0, 300, 250
STYLE DS_CENTER|DS_MODALFRAME|DS_SHELLFONT|WS_CAPTION|WS_VISIBLE|WS_MAXIMIZE|WS_POPUP
CAPTION "output"
FONT 10, "Arial"
{
CONTROL "", IDC_TEXT, MSFTEDIT_CLASS, ES_MULTILINE|ES_READONLY|ES_AUTOHSCROLL|ES_SAVESEL|ES_WANTRETURN|WS_VSCROLL|WS_TABSTOP, 45, 4, 200, 100
DEFPUSHBUTTON "Close", IDCANCEL, 115, 201, 50, 14 // I don't even wanna know how visually horendis this probably looks
PUSHBUTTON "Find... Ctrl+F", IDC_FIND, 1, 94, 40, 20
PUSHBUTTON "Save as... Ctrl+S", IDC_SAVE, 250, 94, 40, 20 // I don't even wanna know how visually horendis this probably looks
}

0 comments on commit a1bfa76

Please sign in to comment.