mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +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
|
||||
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.addch(16);con.curs_right();
|
||||
con.addch(32);con.curs_right();
|
||||
con.color_pair(239,255);
|
||||
con.color_pair(253,255);
|
||||
}
|
||||
else {
|
||||
con.color_pair(253,255);
|
||||
if (errorlevel != 0)
|
||||
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + " [" + errorlevel + "]" + PROMPT_TEXT);
|
||||
else
|
||||
|
||||
@@ -4,12 +4,12 @@ const menubarFile = ["New","Open","Save","Save as","Exit"];
|
||||
const menubarEdit = ["Undo","Redo","Cut","Copy","Paste","Select All","Deselect"];
|
||||
const menubarView = ["Go To Line"];
|
||||
const menubarContents = [menubarFile, menubarEdit, menubarView];
|
||||
const COL_TEXT = 252;
|
||||
const COL_TEXT = 253;
|
||||
const COL_BACK = 255;
|
||||
const COL_SUPERTEXT = 239;
|
||||
const COL_DIMTEXT = 249;
|
||||
const COL_LNUMBACK = 18;
|
||||
const COL_LNUMFORE = 252;
|
||||
const COL_LNUMFORE = 253;
|
||||
const PAINT_START_X = 5;
|
||||
const PAINT_START_Y = 2;
|
||||
|
||||
@@ -55,21 +55,21 @@ function drawInit() {
|
||||
}
|
||||
|
||||
function reset_status() {
|
||||
scroll = 0;
|
||||
textbuffer = [""];
|
||||
cursorRow = 0;
|
||||
cursorCol = 0;
|
||||
cursoringCol = cursorCol;
|
||||
scroll = 0; scrollHor = 0;
|
||||
cursorRow = 0; cursorCol = 0; cursoringCol = cursorCol;
|
||||
}
|
||||
|
||||
// DRAWING FUNCTIONS //
|
||||
|
||||
function drawLineNumbers() {
|
||||
con.curs_set(0);
|
||||
con.color_pair(COL_LNUMFORE, COL_LNUMBACK);
|
||||
for (let y = 0; y < paintHeight; y++) {
|
||||
con.move(y + PAINT_START_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 >= 10) print(` ${lnum} `);
|
||||
else print(` ${lnum} `);
|
||||
@@ -160,8 +160,8 @@ function drawMenubarBase(index) {
|
||||
}
|
||||
|
||||
function drawTextLine(paintRow) {
|
||||
con.color_pair(COL_TEXT, COL_BACK);
|
||||
con.curs_set(0);
|
||||
con.color_pair(COL_TEXT, COL_BACK);
|
||||
for (let x = 0; x < paintWidth; x++) {
|
||||
let text = textbuffer[scroll + paintRow];
|
||||
let charCode =
|
||||
@@ -282,7 +282,7 @@ function prevCol() {
|
||||
}
|
||||
|
||||
function nextRow() {
|
||||
if (cursorRow < textbuffer.length) {
|
||||
if (cursorRow < textbuffer.length - 1) {
|
||||
cursorRow += 1;
|
||||
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
|
||||
|
||||
if (cursorRow >= paintHeight - 1 && cy == paintHeight - 1 + PAINT_START_Y) {
|
||||
scrollHor += 1;
|
||||
scroll += 1;
|
||||
drawTextbuffer();
|
||||
drawLineNumbers();
|
||||
}
|
||||
else if (scroll > 0 && cursorRow == scroll && cy < PAINT_START_Y + 1) {
|
||||
scrollHor -= 1;
|
||||
scroll -= 1;
|
||||
drawTextbuffer();
|
||||
drawLineNumbers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,20 +359,35 @@ while (!exit) {
|
||||
else if (key == con.KEY_BACKSPACE) { // Bksp
|
||||
}
|
||||
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();
|
||||
}
|
||||
else if (key == con.KEY_RIGHT && cursorCol < textbuffer[cursorRow].length) {
|
||||
else if (key == con.KEY_RIGHT) {
|
||||
nextCol(); drawLnCol(); gotoText();
|
||||
}
|
||||
else if (key == con.KEY_UP && cursorRow > 0) {
|
||||
else if (key == con.KEY_UP) {
|
||||
prevRow(); drawLnCol(); gotoText();
|
||||
}
|
||||
else if (key == con.KEY_DOWN && cursorRow < textbuffer.length) {
|
||||
else if (key == con.KEY_DOWN) {
|
||||
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) {
|
||||
cursorCol = 0; scrollHor = 0; cursoringCol = cursorCol;
|
||||
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
||||
@@ -378,6 +395,7 @@ while (!exit) {
|
||||
else if (key == con.KEY_END) {
|
||||
cursorCol = textbuffer[cursorRow].length;
|
||||
scrollHor = textbuffer[cursorRow].length - paintWidth + 2;
|
||||
if (scrollHor < 0) scrollHor = 0;
|
||||
drawTextLine(cursorRow - scroll); drawLnCol(); gotoText();
|
||||
}
|
||||
else if (key >= 32 && key < 128) { // printables (excludes \n)
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.tsvm.VM
|
||||
|
||||
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(
|
||||
"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(
|
||||
"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