wordprocessor wip2

This commit is contained in:
minjaesong
2021-06-08 16:13:11 +09:00
parent e1905f2ca5
commit 82992583ad
4 changed files with 112 additions and 13 deletions

View File

@@ -5,38 +5,133 @@ const COL_DIMTEXT = 249
const COL_LNUMBACK = 18 const COL_LNUMBACK = 18
const COL_LNUMFORE = 253 const COL_LNUMFORE = 253
const COL_CARET_ROW = 81 const COL_CARET_ROW = 81
const PAINT_START_X = 5
const PAINT_START_Y = 2
const BIG_STRIDE = 999 const BIG_STRIDE = 999
const TAB_SIZE = 4 const TAB_SIZE = 4
const PAINT_START_Y = 3
const MEM = system.maxmem()
const caretLeft = 10 const NO_LINEHEAD_PUNCT = [33,34,39,41,44,46,58,59,62,63,93,125]
const caretRight = 80 const NO_LINELAST_PUNCT = [34,39,40,60,91,123]
let PAGE_HEIGHT = 56
let caretLeft = 10
let caretRight = 80
let scroll = 0 let scroll = 0
let scrollHor = 0 let scrollHor = 0
let textbuffer = [""] let textbuffer = ["Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."]
let cursorRow = 0 let cursorRow = 0
let cursorCol = 0 let cursorCol = 0
let page = 0
let exit = false let exit = false
let scene = -1 // -1: main, 0: filemenu, 1: editmenu , ...
let bulletinShown = false let bulletinShown = false
let cursoringCol = 0 let cursoringCol = 0
let filename = "NEWFILE"
let modified = true
let windowWidth = 0 let windowWidth = 0
let windowHeight = 0 let windowHeight = 0
let paintWidth = 0 let paintWidth = 0
let paintHeight = 0 let paintHeight = 0
let scrollPeek = 0 let scrollPeek = 0
let PAINT_START_X = 0
function drawInit() { function drawInit() {
windowWidth = con.getmaxyx()[1] windowWidth = con.getmaxyx()[1]
windowHeight = con.getmaxyx()[0] windowHeight = con.getmaxyx()[0]
paintWidth = windowWidth - PAINT_START_X + 1 PAINT_START_X = caretLeft + 1
paintWidth = caretRight - caretLeft + 1
paintHeight = windowHeight - PAINT_START_Y + 1 paintHeight = windowHeight - PAINT_START_Y + 1
scrollPeek = Math.ceil((paintHeight / 7)) scrollPeek = Math.ceil((paintHeight / 7))
} }
const scrollHorPeek = 1; // to accommodate the scroll indicator const scrollHorPeek = 1; // to accommodate the scroll indicator
function drawMenubar() {
con.move(1,2)
print(`FILE:${(modified) ? '*' : ' '}${filename}`)
}
function drawPRC() {
con.move(1,2+20+6)
print(`PG:${page+1} LN:${cursorRow+1} COL:${cursorCol+1} `)
let rb = MEM - textbuffer.map(it => it.length).reduce((acc,i) => acc + i)
let rp = (rb/100)|0
let s = ` REMAIN:${(rp/10)|0}.${rp%10}K`
con.move(1,windowWidth - s.length)
print(s)
}
function drawTextbuffer(from, toExclusive) {
let lineStart = from || scroll
let lineEnd = toExclusive || scroll + paintHeight
let printbuf = []
for (let i = 0; i < paintHeight; i++) { printbuf.push('') }
let vr = 0; let vc = 0 // virtual row/column
let text = textbuffer.slice(lineStart, lineEnd).join('\n')
serial.println(`paintWidth = ${paintWidth}`)
for (let i = 0; i < text.length; i++) {
let c = text.charCodeAt(i)
let c1 = text.charCodeAt(i+1)
let c2 = text.charCodeAt(i+2)
serial.println(`i:${i} char:'${String.fromCharCode(c,c1)}' Ln ${vr} Col ${vc}`)
if (c == 10) {
vr += 1;vc = 0
printbuf[vr] = ''
}
else if (vc == paintWidth - 1 && NO_LINEHEAD_PUNCT.includes(c1)) {
printbuf[vr] += String.fromCharCode(c, c1)
vr += 1;vc = 0
i += (32 == c2) ? 2 : 1
}
else if (vc == paintWidth - 1 && NO_LINELAST_PUNCT.includes(c)) {
vr += 1;vc = 0
printbuf[vr] += String.fromCharCode(c)
}
else if (vc == paintWidth - 1) {
if (c == 32 || c1 == 32) {
printbuf[vr] += String.fromCharCode(c)
vr += 1;vc = 0
if (c1 == 32) i += 1
}
else {
printbuf[vr] += '-'
vr += 1;vc = 0
printbuf[vr] += String.fromCharCode(c)
vc += 1
}
}
else if (c >= 32) {
printbuf[vr] += String.fromCharCode(c)
vc += 1
}
if (vr > paintHeight || c === undefined) break;
}
for (let y = 0; y < paintHeight; y++) {
con.move(3+y, 1+caretLeft)
print(printbuf[y] || '')
}
gotoText()
}
function gotoText() {
con.move(PAINT_START_Y + cursorRow - scroll, PAINT_START_X + cursorCol - scrollHor)
con.curs_set(1)
}
function drawMain() { function drawMain() {
con.curs_set(0) con.curs_set(0)
@@ -44,6 +139,9 @@ function drawMain() {
con.clear() con.clear()
con.color_pair(COL_TEXT, COL_BACK) con.color_pair(COL_TEXT, COL_BACK)
drawMenubar()
drawPRC()
// column indicator // column indicator
con.move(2,1) con.move(2,1)
for (let k = 0; k < 9; k++) print(`${k}....:....`) for (let k = 0; k < 9; k++) print(`${k}....:....`)
@@ -51,8 +149,9 @@ function drawMain() {
con.mvaddch(2,1+caretLeft,91) con.mvaddch(2,1+caretLeft,91)
con.mvaddch(2,1+caretRight,93) con.mvaddch(2,1+caretRight,93)
con.color_pair(COL_BACK, COL_TEXT) con.color_pair(COL_TEXT, COL_BACK)
} }
drawMain() drawMain()
drawTextbuffer(0)

View File

@@ -30,7 +30,7 @@ public class AppLoader {
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, BasicRom.INSTANCE}); //VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, BasicRom.INSTANCE});
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{OEMBios.INSTANCE, BasicRom.INSTANCE}); //VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{OEMBios.INSTANCE, BasicRom.INSTANCE});
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TandemBios.INSTANCE, BasicRom.INSTANCE}); //VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TandemBios.INSTANCE, BasicRom.INSTANCE});
VM vm = new VM(256 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, WPBios.INSTANCE}); VM vm = new VM(128 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, WPBios.INSTANCE});
// uncomment to target the TerranBASIC runner // uncomment to target the TerranBASIC runner
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TBASRelBios.INSTANCE}); //VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TBASRelBios.INSTANCE});

View File

@@ -578,7 +578,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
} }
private var textCursorBlinkTimer = 0f private var textCursorBlinkTimer = 0f
private val textCursorBlinkInterval = 0.5f private val textCursorBlinkInterval = 0.25f
private var textCursorIsOn = true private var textCursorIsOn = true
private var glowDecay = config.decay private var glowDecay = config.decay
private var decayColor = Color(1f, 1f, 1f, 1f - glowDecay) private var decayColor = Color(1f, 1f, 1f, 1f - glowDecay)
@@ -744,7 +744,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
textCursorBlinkTimer += delta textCursorBlinkTimer += delta
if (textCursorBlinkTimer > textCursorBlinkInterval) { if (textCursorBlinkTimer > textCursorBlinkInterval) {
textCursorBlinkTimer -= 0.5f textCursorBlinkTimer -= 0.25f
textCursorIsOn = !textCursorIsOn textCursorIsOn = !textCursorIsOn
} }

View File

@@ -28,7 +28,7 @@ open class TexticsAdapter(vm: VM, config: AdapterConfig = AdapterConfig(
companion object { companion object {
val crtColor = hashMapOf( val crtColor = hashMapOf(
"white" to Color(0xe4eaffff.toInt()), "white" to Color(0xe4eaffff.toInt()),
"amber" to Color(0xffb700ff.toInt()), "amber" to Color(0xffd600ff.toInt()),
"green" to Color(0x4aff00ff) "green" to Color(0x4aff00ff)
) )
} }