--- nono/lib/textscreen.cpp 2026/04/29 17:04:31 1.1.1.2 +++ nono/lib/textscreen.cpp 2026/04/29 17:04:37 1.1.1.4 @@ -1,9 +1,9 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "header.h" #include "textscreen.h" // @@ -48,25 +48,13 @@ TextScreen::Clear() textbuf[i] = 0x0020; } - // 折り返しモードならクリアでホームポジションへ - if (foldmode) { - Locate(0, 0); - } -} - -// 現在位置を移動 -void -TextScreen::Locate(int x, int y) -{ - X = x; - Y = y; + // ホームポジション + Locate(0, 0); } // 現在のカーソル位置に1文字出力する。 -// カーソルは一つ移動する。 -// foldmode = false なら、移動後右もしくは下にはみ出しても何もしない。 -// foldmode = true なら、右にはみ出した場合は次行左端に移動、 -// 下にはみ出した場合はカーソル位置はそのままで上に1行スクロールさせる。 +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 +// XXX どっかで拾えてもいいような void TextScreen::Putc(uint16 ch) { @@ -74,22 +62,12 @@ TextScreen::Putc(uint16 ch) return; } - if (ch == '\n') { - CRLF(); - } else { - textbuf[(Y * col) + X] = ch; - X++; - - // 折り返しモード - if (foldmode && X >= col) { - CRLF(); - } - } + textbuf[(Y * col) + X] = ch; + X++; } // テキストスクリーンに文字列を出力する。 -// 右もしくは下にはみ出した場合は無視する。 -// XXX どっかで拾えてもいいような +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 void TextScreen::Puts(const char *str) { @@ -99,16 +77,17 @@ TextScreen::Puts(const char *str) } // テキストスクリーンに文字列を出力する。 -// 右もしくは下にはみ出した場合は無視する。 +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 void -TextScreen::Puts(uint attr, const char *str) +TextScreen::Puts(TA attr, const char *str) { while (*str != '\0') { - Putc(attr | *str++); + Putc(((uint)attr) | *str++); } } // テキストスクリーンの現在位置から書式付き文字列を出力する。 +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 void TextScreen::Print(const char *fmt, ...) { @@ -123,6 +102,7 @@ TextScreen::Print(const char *fmt, ...) } // テキストスクリーンに座標を指定して書式付き文字列を出力する。 +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 void TextScreen::Print(int x, int y, const char *fmt, ...) { @@ -138,8 +118,9 @@ TextScreen::Print(int x, int y, const ch } // テキストスクリーンに座標と属性を指定して、書式付き文字列を出力する。 +// 出力後カーソルは移動する。移動後画面からはみ出しても何もしない。 void -TextScreen::Print(int x, int y, uint attr, const char *fmt, ...) +TextScreen::Print(int x, int y, TA attr, const char *fmt, ...) { char buf[1024]; va_list ap; @@ -152,9 +133,48 @@ TextScreen::Print(int x, int y, uint att Puts(attr, buf); } +// +// テキストコンソール +// (行折り返しと行送りがある) +// + +// コンストラクタ +TextConsole::TextConsole() + : inherited() +{ +} + +// デストラクタ +TextConsole::~TextConsole() +{ +} + +// 現在のカーソル位置に1文字出力する。 +// 出力後カーソルは移動する。 +// 移動した結果右にはみ出した場合は次行左端に移動、 +// 下にはみ出した場合はカーソル位置はそのままで上に1行スクロールさせる。 +void +TextConsole::Putc(uint16 ch) +{ + if (X >= col || Y >= row) { + return; + } + + if (ch == '\n') { + CRLF(); + } else { + textbuf[(Y * col) + X] = ch; + X++; + + if (X >= col) { + CRLF(); + } + } +} + // 改行 void -TextScreen::CRLF() +TextConsole::CRLF() { X = 0; Y++;