Import Ebitor 0.1.1 upstream source snapshot

Original author: Pierre Sarrazin.
Source: http://sarrazip.com/dev/ebitor-0.1.1.tar.gz
Archive SHA-256: 6911a9d2ee80925622f1d82db1b77710a1f896865e63d29a04dc16489b150e83
This commit is contained in:
Brian Holman committed 2026-11-09 23:45:41 -07:00
commit 53bf6abdd5
19 files changed
+5400

No files matched your search

+153
View File
@@ -0,0 +1,153 @@
/* smoldemo.c - Minimal demo of the Ebitor full screen text editor.
By Pierre Sarrazin <http://sarrazip.com/>
This file is in the public domain.
*/
#include "sg4term.h" /* 32x16 terminal to be used by the editor */
#include "Ebitor.h" /* the editor */
#include <assert.h>
///////////////////////////////////////////////////////////////
enum
{
BASIC_TIMER_ADDRESS = 0x112, // incremented 60 times per second by Basic IRQ routine
BASIC_32X16_SCREEN = 0x0400, // address of 32x16 screen buffer
};
// Contains the edited text.
//
char textBuffer[600];
// newStatus: Must be shorter than the terminal width.
// Does not move the terminal cursor.
//
static void
setStatus(const ebitor_Window *window, const char *newStatus)
{
byte origCursorCol, origCursorRow;
sg4term_getCursorPos(&origCursorCol, &origCursorRow);
sg4term_locate(0, window->height); // cursor deliberately on row below window
sg4term_invertColors();
sg4term_eraseCurrentLine(); // also puts cursor at start of line
sg4term_print(newStatus);
sg4term_invertColors();
sg4term_locate(origCursorCol, origCursorRow);
}
static void
showHelp(const ebitor_Window *window)
{
sg4term_clear();
setStatus(window, "HELP PAGE");
sg4term_locate(0, 0);
sg4term_print(
"BACKSPACE IS THE CLEAR KEY.\r"
"\r"
"COMMANDS AFTER PRESSING BREAK:"
"\r"
"Q: QUIT THIS EDITOR\r"
"H: SHOW THIS HELP PAGE\r"
"\r"
"PRESS A KEY TO CONTINUE: ");
sg4term_waitEditorKey();
}
static byte
inkey1(void *cookie)
{
return inkey();
}
// Does not animate a cursor.
//
byte
waitUpperCaseKey(void)
{
byte key;
while ((key = (byte) toupper(inkey())) == 0)
;
return key;
}
int
main()
{
width(32); // on a CoCo 3, switches to 32x16 if not already in that mode
rgb(); // on a CoCo 3, resets the palette in case it is not at the default
ebitor_Window window;
window.cursorCol = window.cursorRow = 0;
// Specify a window for the editor.
// A border is left unused, to show that the sg4 driver
// can use a subwindow of the screen.
// Excludes the status line, which this demo renders below this window.
window.width = 32 - 2;
window.height = 16 - 3;
window.leftCol = 1;
window.topRow = 1;
width(32); // by SECB
cls(3);
sg4term_init((char *) BASIC_32X16_SCREEN, &window,
inkey1, NULL, (word *) BASIC_TIMER_ADDRESS);
Ebitor_init(textBuffer, sizeof(textBuffer),
window.width, window.height,
sg4term_clear,
sg4term_locate,
sg4term_getCursorPos,
sg4term_print,
sg4term_printPrefix,
sg4term_clrtoeol,
sg4term_scrollWindowUp,
sg4term_scrollWindowDown,
sg4term_waitEditorKey);
// Main editing loop.
//
for (BOOL refresh = TRUE, resetStatus = TRUE; ; )
{
if (resetStatus)
setStatus(&window, "PRESS BREAK FOR MENU");
else
resetStatus = TRUE;
Ebitor_processEditing(refresh);
refresh = FALSE;
setStatus(&window, "Q=QUIT, H=HELP");
byte key = waitUpperCaseKey();
if (key == 3) // if break key
continue; // back to processing
if (key == 'Q')
break; // quit
switch ((char) key)
{
case 'H':
showHelp(&window);
refresh = TRUE;
break;
}
}
Ebitor_shutdown();
cls(255); // equivalent to Basic's CLS command without an argument
printf("FINAL TEXT:\n\n%s\n", textBuffer);
return 0;
}