mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-06 05:28:31 +09:00
edit.js: text nav in all four directions, home/end behaviour on shorter-than-screen-width line fixed, pageup/pagedown nav impl; default text colour is tad brighter
This commit is contained in:
2
COPYING
2
COPYING
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2020 CuriousTorvald
|
Copyright (c) 2020-2021 CuriousTorvald
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -32,9 +32,10 @@ function print_prompt_text() {
|
|||||||
con.color_pair(253,255);
|
con.color_pair(253,255);
|
||||||
con.addch(16);con.curs_right();
|
con.addch(16);con.curs_right();
|
||||||
con.addch(32);con.curs_right();
|
con.addch(32);con.curs_right();
|
||||||
con.color_pair(239,255);
|
con.color_pair(253,255);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
con.color_pair(253,255);
|
||||||
if (errorlevel != 0)
|
if (errorlevel != 0)
|
||||||
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + " [" + errorlevel + "]" + PROMPT_TEXT);
|
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + " [" + errorlevel + "]" + PROMPT_TEXT);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ const menubarFile = ["New","Open","Save","Save as","Exit"];
|
|||||||
const menubarEdit = ["Undo","Redo","Cut","Copy","Paste","Select All","Deselect"];
|
const menubarEdit = ["Undo","Redo","Cut","Copy","Paste","Select All","Deselect"];
|
||||||
const menubarView = ["Go To Line"];
|
const menubarView = ["Go To Line"];
|
||||||
const menubarContents = [menubarFile, menubarEdit, menubarView];
|
const menubarContents = [menubarFile, menubarEdit, menubarView];
|
||||||
const COL_TEXT = 252;
|
const COL_TEXT = 253;
|
||||||
const COL_BACK = 255;
|
const COL_BACK = 255;
|
||||||
const COL_SUPERTEXT = 239;
|
const COL_SUPERTEXT = 239;
|
||||||
const COL_DIMTEXT = 249;
|
const COL_DIMTEXT = 249;
|
||||||
const COL_LNUMBACK = 18;
|
const COL_LNUMBACK = 18;
|
||||||
const COL_LNUMFORE = 252;
|
const COL_LNUMFORE = 253;
|
||||||
const PAINT_START_X = 5;
|
const PAINT_START_X = 5;
|
||||||
const PAINT_START_Y = 2;
|
const PAINT_START_Y = 2;
|
||||||
|
|
||||||
@@ -55,21 +55,21 @@ function drawInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reset_status() {
|
function reset_status() {
|
||||||
scroll = 0;
|
|
||||||
textbuffer = [""];
|
textbuffer = [""];
|
||||||
cursorRow = 0;
|
scroll = 0; scrollHor = 0;
|
||||||
cursorCol = 0;
|
cursorRow = 0; cursorCol = 0; cursoringCol = cursorCol;
|
||||||
cursoringCol = cursorCol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DRAWING FUNCTIONS //
|
// DRAWING FUNCTIONS //
|
||||||
|
|
||||||
function drawLineNumbers() {
|
function drawLineNumbers() {
|
||||||
|
con.curs_set(0);
|
||||||
con.color_pair(COL_LNUMFORE, COL_LNUMBACK);
|
con.color_pair(COL_LNUMFORE, COL_LNUMBACK);
|
||||||
for (let y = 0; y < paintHeight; y++) {
|
for (let y = 0; y < paintHeight; y++) {
|
||||||
con.move(y + PAINT_START_Y, 1);
|
con.move(y + PAINT_START_Y, 1);
|
||||||
let lnum = scroll + y + 1;
|
let lnum = scroll + y + 1;
|
||||||
if (lnum >= 1000) print(`${lnum}`);
|
if (lnum - 1 >= textbuffer.length) print(' ');
|
||||||
|
else if (lnum >= 1000) print(`${lnum}`);
|
||||||
else if (lnum >= 100) print(`${lnum} `);
|
else if (lnum >= 100) print(`${lnum} `);
|
||||||
else if (lnum >= 10) print(` ${lnum} `);
|
else if (lnum >= 10) print(` ${lnum} `);
|
||||||
else print(` ${lnum} `);
|
else print(` ${lnum} `);
|
||||||
@@ -160,8 +160,8 @@ function drawMenubarBase(index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawTextLine(paintRow) {
|
function drawTextLine(paintRow) {
|
||||||
con.color_pair(COL_TEXT, COL_BACK);
|
|
||||||
con.curs_set(0);
|
con.curs_set(0);
|
||||||
|
con.color_pair(COL_TEXT, COL_BACK);
|
||||||
for (let x = 0; x < paintWidth; x++) {
|
for (let x = 0; x < paintWidth; x++) {
|
||||||
let text = textbuffer[scroll + paintRow];
|
let text = textbuffer[scroll + paintRow];
|
||||||
let charCode =
|
let charCode =
|
||||||
@@ -282,7 +282,7 @@ function prevCol() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nextRow() {
|
function nextRow() {
|
||||||
if (cursorRow < textbuffer.length) {
|
if (cursorRow < textbuffer.length - 1) {
|
||||||
cursorRow += 1;
|
cursorRow += 1;
|
||||||
updateScrollState(false, true);
|
updateScrollState(false, true);
|
||||||
}
|
}
|
||||||
@@ -320,12 +320,14 @@ function updateScrollState(hor, vert) {
|
|||||||
cursorCol = Math.min(tlen, cursoringCol); // move the column pointer intelligently, just like any decent text editor would do
|
cursorCol = Math.min(tlen, cursoringCol); // move the column pointer intelligently, just like any decent text editor would do
|
||||||
|
|
||||||
if (cursorRow >= paintHeight - 1 && cy == paintHeight - 1 + PAINT_START_Y) {
|
if (cursorRow >= paintHeight - 1 && cy == paintHeight - 1 + PAINT_START_Y) {
|
||||||
scrollHor += 1;
|
scroll += 1;
|
||||||
drawTextbuffer();
|
drawTextbuffer();
|
||||||
|
drawLineNumbers();
|
||||||
}
|
}
|
||||||
else if (scroll > 0 && cursorRow == scroll && cy < PAINT_START_Y + 1) {
|
else if (scroll > 0 && cursorRow == scroll && cy < PAINT_START_Y + 1) {
|
||||||
scrollHor -= 1;
|
scroll -= 1;
|
||||||
drawTextbuffer();
|
drawTextbuffer();
|
||||||
|
drawLineNumbers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,20 +359,35 @@ while (!exit) {
|
|||||||
else if (key == con.KEY_BACKSPACE) { // Bksp
|
else if (key == con.KEY_BACKSPACE) { // Bksp
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_RETURN) { // Return
|
else if (key == con.KEY_RETURN) { // Return
|
||||||
appendLine(); drawLnCol(); gotoText();
|
appendLine(); drawLineNumbers(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_LEFT && cursorCol > 0) {
|
else if (key == con.KEY_LEFT) {
|
||||||
prevCol(); drawLnCol(); gotoText();
|
prevCol(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_RIGHT && cursorCol < textbuffer[cursorRow].length) {
|
else if (key == con.KEY_RIGHT) {
|
||||||
nextCol(); drawLnCol(); gotoText();
|
nextCol(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_UP && cursorRow > 0) {
|
else if (key == con.KEY_UP) {
|
||||||
prevRow(); drawLnCol(); gotoText();
|
prevRow(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key == con.KEY_DOWN && cursorRow < textbuffer.length) {
|
else if (key == con.KEY_DOWN) {
|
||||||
nextRow(); drawLnCol(); gotoText();
|
nextRow(); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
|
else if (key == con.KEY_PAGE_UP) {
|
||||||
|
cursorRow -= paintHeight - 1;
|
||||||
|
scroll -= paintHeight - 1;
|
||||||
|
if (cursorRow < 0) cursorRow = 0;
|
||||||
|
if (scroll < 0) scroll = 0;
|
||||||
|
drawTextbuffer(); drawLineNumbers(); drawLnCol(); gotoText();
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_PAGE_DOWN) {
|
||||||
|
cursorRow += paintHeight - 1;
|
||||||
|
scroll += paintHeight - 1;
|
||||||
|
if (cursorRow > textbuffer.length - 1) cursorRow = textbuffer.length - 1;
|
||||||
|
if (scroll > textbuffer.length - paintHeight + 2) scroll = textbuffer.length - paintHeight + 2;
|
||||||
|
else if (scroll < 0) scroll = 0;
|
||||||
|
drawTextbuffer(); drawLineNumbers(); drawLnCol(); gotoText();
|
||||||
|
}
|
||||||
else if (key == con.KEY_HOME) {
|
else if (key == con.KEY_HOME) {
|
||||||
cursorCol = 0; scrollHor = 0; cursoringCol = cursorCol;
|
cursorCol = 0; scrollHor = 0; cursoringCol = cursorCol;
|
||||||
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
||||||
@@ -378,6 +395,7 @@ while (!exit) {
|
|||||||
else if (key == con.KEY_END) {
|
else if (key == con.KEY_END) {
|
||||||
cursorCol = textbuffer[cursorRow].length;
|
cursorCol = textbuffer[cursorRow].length;
|
||||||
scrollHor = textbuffer[cursorRow].length - paintWidth + 2;
|
scrollHor = textbuffer[cursorRow].length - paintWidth + 2;
|
||||||
|
if (scrollHor < 0) scrollHor = 0;
|
||||||
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
else if (key >= 32 && key < 128) { // printables (excludes \n)
|
else if (key >= 32 && key < 128) { // printables (excludes \n)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
|
|
||||||
class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
||||||
"pmlcd_inverted", 240, 64, 40, 8, 252, 255, 262144L, "lcd2.png", 0.7f, TEXT_TILING_SHADER_LCD, DRAW_SHADER_FRAG_LCD, 2f
|
"pmlcd_inverted", 240, 64, 40, 8, 253, 255, 262144L, "lcd2.png", 0.7f, TEXT_TILING_SHADER_LCD, DRAW_SHADER_FRAG_LCD, 2f
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|||||||
@@ -1250,11 +1250,11 @@ void main() {
|
|||||||
|
|
||||||
val DEFAULT_CONFIG_COLOR_CRT = AdapterConfig(
|
val DEFAULT_CONFIG_COLOR_CRT = AdapterConfig(
|
||||||
"crt_color",
|
"crt_color",
|
||||||
560, 448, 80, 32, 252, 255, 256.kB(), "FontROM7x14.png", 0.32f, TEXT_TILING_SHADER_COLOUR
|
560, 448, 80, 32, 253, 255, 256.kB(), "FontROM7x14.png", 0.32f, TEXT_TILING_SHADER_COLOUR
|
||||||
)
|
)
|
||||||
val DEFAULT_CONFIG_PMLCD = AdapterConfig(
|
val DEFAULT_CONFIG_PMLCD = AdapterConfig(
|
||||||
"pmlcd_inverted",
|
"pmlcd_inverted",
|
||||||
560, 448, 80, 32, 252, 255, 256.kB(), "FontROM7x14.png", 0.64f, TEXT_TILING_SHADER_LCD, DRAW_SHADER_FRAG_LCD
|
560, 448, 80, 32, 253, 255, 256.kB(), "FontROM7x14.png", 0.64f, TEXT_TILING_SHADER_LCD, DRAW_SHADER_FRAG_LCD
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user