• R/O
  • SSH
  • HTTPS

nos: Commit


Commit MetaInfo

Révision360 (tree)
l'heure2009-10-22 19:32:45
Auteuruchan_nos

Message de Log

コマンド改良
コンソールウィンドウのカーソル表示

Change Summary

Modification

--- bitnos5/trunk/kernel/console.cpp (revision 359)
+++ bitnos5/trunk/kernel/console.cpp (revision 360)
@@ -10,6 +10,10 @@
1010 #include <bitnos/sheet.h>
1111 #include <bitnos/window.h>
1212 #include <string.h>
13+#include <stdio.h>
14+#include <bitnos/memory.h>
15+#include <bitnos/timer.h>
16+#include <bitnos/specialtask.h>
1317
1418 namespace TaskConsole
1519 {
@@ -22,6 +26,10 @@
2226
2327 char cmdline[128];
2428 int cmdlineBegin;
29+
30+ Timer* tim;
31+ bool cursor;
32+ bool active;
2533 };
2634
2735 // コマンド実行機能なし
@@ -32,10 +40,15 @@
3240
3341 void PutString0(Valiables* o, const char* str);
3442
43+void PutString0(Valiables* o, const char* str, int len);
44+
3545 void ConsoleRefreshScreen(Valiables* o, int begin);
3646
3747 void RunCommand(Valiables* o);
3848
49+void ShowCursor(Valiables* o);
50+void EraseCursor(Valiables* o);
51+
3952 void Init(void* obj)
4053 {
4154 Valiables* o = (Valiables*)obj;
@@ -44,10 +57,14 @@
4457
4558 Debug::WriteLine("Console Init");
4659
47- o->cons.height = 10;
48- o->cons.width = 29;
49- o->cons.bufHeight = 100;
50- o->cons.bufWidth = 29;
60+ //o->cons.height = 10;
61+ o->cons.height = 16;
62+ // o->cons.width = 29;
63+ o->cons.width = 50;
64+ //o->cons.bufHeight = 100;
65+ o->cons.bufHeight = o->cons.height;
66+ //o->cons.bufWidth = 29;
67+ o->cons.bufWidth = o->cons.width;
5168 o->cons.buf = new char[o->cons.bufHeight * o->cons.bufWidth];
5269 o->cons.startLine = o->cons.endLine = 0;
5370 o->cons.xPos = 0;
@@ -54,6 +71,8 @@
5471 o->cons.backColor = ConvRGB16(0, 0, 0);
5572 o->cons.textColor = ConvRGB16(255, 255, 255);
5673 o->cmdlineBegin = 0;
74+ o->cursor = false;
75+ o->active = SpecialTask::Get(SpecialTask::Active) == task;
5776
5877 o->img = new Image(
5978 8 + fontHankaku->GetWidth() * o->cons.width,
@@ -66,6 +85,9 @@
6685 o->sht->SetParentTask(task);
6786 shtman->SetHeight(o->sht, 0, Sheet::Normal);
6887
88+ o->tim = timman->Alloc(task, 1);
89+ o->tim->SetTime(80);
90+
6991 PutChar(o, '>');
7092 }
7193
@@ -75,8 +97,36 @@
7597
7698 if (msg->from == Message::From::Keyboard) {
7799 if (msg->arg1 != 0) {
100+ if (o->cursor) {
101+ EraseCursor(o);
102+ }
78103 PutChar(o, msg->arg1);
104+ if (o->cursor) {
105+ ShowCursor(o);
106+ }
79107 }
108+ } else if (msg->from == Message::From::Timer) {
109+ if (msg->arg1 == 1) {
110+ if (o->active) {
111+ o->tim->SetTime(70);
112+ if (o->cursor) {
113+ EraseCursor(o);
114+ o->cursor = false;
115+ } else {
116+ ShowCursor(o);
117+ o->cursor = true;
118+ }
119+ }
120+ }
121+ } else if (msg->from == Message::From::System) {
122+ if (msg->arg1 == Message::System::WindowActivated) {
123+ o->active = true;
124+ o->tim->SetTime(20);
125+ ShowCursor(o);
126+ } else if (msg->arg1 == Message::System::WindowInactivated) {
127+ o->active = false;
128+ EraseCursor(o);
129+ }
80130 }
81131 }
82132
@@ -88,8 +138,14 @@
88138 o->cons.xPos++;
89139 }
90140 if (ch == '\b') {
91- if (o->cons.xPos > 0) {
141+ if (o->cons.endLine != o->cmdlineBegin) {
92142 o->cons.xPos--;
143+ if (o->cons.xPos < 0) {
144+ o->cons.xPos = o->cons.bufWidth - 1;
145+ o->cons.endLine--;
146+ }
147+ } else if (o->cons.endLine == o->cmdlineBegin && o->cons.xPos > 1) {
148+ o->cons.xPos--;
93149 }
94150 o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0';
95151 // 1文字だけ消去する
@@ -241,6 +297,14 @@
241297 }
242298 }
243299
300+void PutString0(Valiables* o, const char* str, int len)
301+{
302+ while (len > 0 && *str != '\0') {
303+ PutChar0(o, *str++);
304+ len--;
305+ }
306+}
307+
244308 void ConsoleRefreshScreen(Valiables* o, int begin)
245309 {
246310 int lines = o->cons.height;
@@ -297,8 +361,42 @@
297361
298362 void RunCommand(Valiables* o)
299363 {
364+ char s[256];
300365 if (strncmp(o->cmdline, "mem", 4) == 0) {
301- PutString0(o, "can't calculate memory size\n");
366+ PutString0(o, "mem : ");
367+ sprintf(s, "%10d", physicalMemorySize);
368+ if ((physicalMemorySize >> 30) != 0) {
369+ PutString0(o, s + 0, 1);
370+ PutChar0(o, ',');
371+ }
372+ if ((physicalMemorySize >> 20) != 0) {
373+ PutString0(o, s + 1, 3);
374+ PutChar0(o, ',');
375+ }
376+ if ((physicalMemorySize >> 10) != 0) {
377+ PutString0(o, s + 4, 3);
378+ PutChar0(o, ',');
379+ }
380+ PutString0(o, s + 7, 3);
381+ PutString0(o, " B\n");
382+
383+ uint32_t freeSize = memman.GetFreeSize();
384+ PutString0(o, "free : ");
385+ sprintf(s, "%10d", freeSize);
386+ if ((freeSize >> 30) != 0) {
387+ PutString0(o, s + 0, 1);
388+ PutChar0(o, ',');
389+ }
390+ if ((freeSize >> 20) != 0) {
391+ PutString0(o, s + 1, 3);
392+ PutChar0(o, ',');
393+ }
394+ if ((freeSize >> 10) != 0) {
395+ PutString0(o, s + 4, 3);
396+ PutChar0(o, ',');
397+ }
398+ PutString0(o, s + 7, 3);
399+ PutString0(o, " B\n");
302400 } else if (strncmp(o->cmdline, "opencons", 9) == 0) {
303401 Task* consTask = taskman->Alloc();
304402 uintptr_t stackTop;
@@ -313,4 +411,41 @@
313411 }
314412 }
315413
414+void ShowCursor(Valiables* o)
415+{
416+ int end = o->cons.endLine;
417+ if (end >= o->cons.height) {
418+ end = o->cons.height - 1;
419+ }
420+ Point pos;
421+ if (o->cons.xPos > 0) {
422+ pos = Point(4 + o->cons.xPos * fontHankaku->GetWidth(), 25 + 4 + end * fontHankaku->GetHeight());
423+ } else {
424+ pos = Point(4 + o->cons.width * fontHankaku->GetWidth(), 25 + 4 + (end - 1) * fontHankaku->GetHeight());
425+ }
426+ o->sht->DrawRectangleFill(
427+ o->cons.textColor,
428+ pos,
429+ pos + Point(0, fontHankaku->GetHeight() - 1));
316430 }
431+
432+void EraseCursor(Valiables* o)
433+{
434+ int end = o->cons.endLine;
435+ if (end >= o->cons.height) {
436+ end = o->cons.height - 1;
437+ }
438+ Point pos;
439+ if (o->cons.xPos > 0) {
440+ pos = Point(4 + o->cons.xPos * fontHankaku->GetWidth(), 25 + 4 + end * fontHankaku->GetHeight());
441+ } else {
442+ pos = Point(4 + o->cons.width * fontHankaku->GetWidth(), 25 + 4 + (end - 1) * fontHankaku->GetHeight());
443+ }
444+ o->sht->DrawRectangleFill(
445+ o->cons.backColor,
446+ pos,
447+ pos + Point(1, fontHankaku->GetHeight() - 1));
448+}
449+
450+
451+}
Afficher sur ancien navigateur de dépôt.