On Sat, Nov 14 14:28, Kevin Wolf wrote: > + setup: Ein tolles Konfigurationsprogramm, das im Moment so gut wie > gar nichts kann > > Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx> > --- > src/modules/pas/setup/Makefile.all | 4 + > src/modules/pas/setup/menu.pas | 96 ++++++++++++++++++++ > src/modules/pas/setup/setup.pas | 52 +++++++++++ > src/modules/pas/setup/setup_keyboard.pas | 146 ++++++++++++++++++++++++++++++ > src/modules/pas/setup/setup_lpt.pas | 136 ++++++++++++++++++++++++++++ > 5 files changed, 434 insertions(+), 0 deletions(-) > create mode 100644 src/modules/pas/setup/Makefile.all > create mode 100644 src/modules/pas/setup/menu.pas > create mode 100644 src/modules/pas/setup/setup.pas > create mode 100644 src/modules/pas/setup/setup_keyboard.pas > create mode 100644 src/modules/pas/setup/setup_lpt.pas > > diff --git a/src/modules/pas/setup/Makefile.all b/src/modules/pas/setup/Makefile.all > new file mode 100644 > index 0000000..febfb1e > --- /dev/null > +++ b/src/modules/pas/setup/Makefile.all > @@ -0,0 +1,4 @@ > +shopt -s extglob > +echo "LD $1/setup" > +"$COMPILER_PREFIX"ld -m elf_i386 -osetup -Ttext=0x40000000 *.o --start-group ../lib/units/*.a $2 --end-group `gcc -print-libgcc-file-name` > +strip -s setup -o $1/apps/setup > diff --git a/src/modules/pas/setup/menu.pas b/src/modules/pas/setup/menu.pas > new file mode 100644 > index 0000000..89b537d > --- /dev/null > +++ b/src/modules/pas/setup/menu.pas > @@ -0,0 +1,96 @@ > +unit menu; > + > +interface > +uses tui; > + > +procedure MainMenu(screen: TUIObject; frame: TUIFrame); > +function StartModule(module: String; back: boolean): boolean; > + > +implementation > + > +uses tyndur, crt, setup_keyboard, setup_lpt; > + > +function StartModule(module: String; back: boolean): boolean; > +begin > + if module = 'keyboard' then begin > + SetupKeyboard(back); > + end else if module = 'lpt' then begin > + SetupLPT(back); > + end else begin > + exit(false); > + end; > + > + exit(true); > +end; > + > +procedure MainMenu(screen: TUIObject; frame: TUIFrame); > +var > + mainw: TUIRowContainer; > + > + a: TUIMenu; > + b: TUILabel; > + > + buttons: TUIColContainer; > + btnOk: TUIButton; > + btnCancel: TUIButton; > +begin > + mainw := TUIRowContainer.create(2); > + mainw.spacer := true; > + frame.obj := mainw; > + > + a := TUIMenu.create(4); > + with a do begin > + bgcolor := 0; > + color := 14; > + > + AddItem('Tastaturbelegung', nil); > + AddItem('lpt-Quellen', nil); > + AddItem('', nil); > + AddItem('Beenden', nil); > + end; > + mainw[1] := a; > + mainw.fixed[1] := 4; > + > + b := TUILabel.create; > + b.content := Utf8Decode('Bitte w??hle aus dem Men?? das gew??nschte Konfigurationsprogramm aus.'); > + mainw[0] := b; > + mainw.prop[0] := 30; > + > + a.selected := 0; > + repeat > + // Zeichnen > + screen.align(80, 24); > + screen.draw(1, 1); > + > + case readkey of > + #27: > + case ReadEscapeSequence of > + SK_UP: > + begin > + a.selected := (a.selected + 4 - 1) mod 4; > + if a.selected = 2 then begin > + a.selected := 1; > + end; > + end; > + SK_DOWN: > + begin > + a.selected := (a.selected + 1) mod 4; > + if a.selected = 2 then begin > + a.selected := 3; > + end; > + end; > + end; > + #10: > + case a.selected of > + 0: StartModule('keyboard', true); > + 1: StartModule('lpt', true); > + 3: break; > + end; > + end; > + until false; > + > + frame.obj := nil; > + mainw.free; > +end; > + > +end. > diff --git a/src/modules/pas/setup/setup.pas b/src/modules/pas/setup/setup.pas > new file mode 100644 > index 0000000..e50a90a > --- /dev/null > +++ b/src/modules/pas/setup/setup.pas > @@ -0,0 +1,52 @@ > +program setup; > +{$MODE ObjFPC} > +{$H+} > + > +uses > + crt, tui, > + menu; > + > +var > + screen: TUIRowContainer; > + title: TUILabel; > + f: TUIFrame; > + s: string; > + show_menu: boolean; > + i: integer; > +begin > + s := ''; > + WriteLn(HexStr(dword(@s), 8)); Was soll denn das genau? ;-) > + > + screen := TUIRowContainer.create(2); > + screen.bgcolor := 2; > + screen.color := 1; > + > + title := TUILabel.create; > + title.content := 'tyndur-Konfiguration'; > + title.bgcolor := 1; > + title.color := 15; > + screen[0] := title; > + screen.fixed[0] := 1; > + > + f := TUIFrame.create(nil, 60, 12); > + screen[1] := f; > + screen.prop[1] := 1; > + > + show_menu := true; > + for i := 1 to system.ParamCount do begin > + if not StartModule(system.ParamStr(i), false) then begin > + show_menu := false; > + break; > + end; > + end; > + > + if show_menu then begin > + MainMenu(screen, f); > + end; > + > + screen.free; > + > + TextBackground(0); > + TextColor(7); > + ClrScr; > +end. > diff --git a/src/modules/pas/setup/setup_keyboard.pas b/src/modules/pas/setup/setup_keyboard.pas > new file mode 100644 > index 0000000..879ca88 > --- /dev/null > +++ b/src/modules/pas/setup/setup_keyboard.pas > @@ -0,0 +1,146 @@ > +unit setup_keyboard; > + > +interface > + > +procedure SetupKeyboard(back: boolean); > + > +implementation > + > +uses sysutils, tyndur, crt, tui; > + > +procedure SetLayout(layout: String); > +var > + f: File of byte; > + buf: Array [1..2048] of byte; > + path: String; > + > + cfg: text; > +begin > + path := 'file:/system/keymaps/' + layout + '.kbd'; > + > + if not FileExists(path) then begin > + exit; > + end; > + > + Assign(f, path); > + Reset(f, 2048); > + BlockRead(f, buf, 1); > + Close(f); > + > + Assign(f, 'vterm:/keymap'); > + Rewrite(f, 2048); > + BlockWrite(f, buf, 1); > + Close(f); > +end; > + > +procedure SetupKeyboard(back: boolean); > +var > + mainw: TUIRowContainer; > + > + a: TUIMenu; > + b: TUILabel; > + > + buttons: TUIColContainer; > + btnOk: TUIButton; > + btnCancel: TUIButton; > + screen: TUIRowContainer; > + title: TUILabel; > + f: TUIFrame; > + s: string; > + num_items: integer; > +begin > + s := ''; > + WriteLn(HexStr(dword(@s), 8)); Nochmal... ;-) > + > + screen := TUIRowContainer.create(2); > + screen.bgcolor := 2; > + screen.color := 1; > + > + title := TUILabel.create; > + title.content := 'tyndur-Konfiguration: Tastaturbelegung'; > + title.bgcolor := 1; > + title.color := 15; > + screen[0] := title; > + screen.fixed[0] := 1; > + > + f := TUIFrame.create(nil, 60, 12); > + screen[1] := f; > + screen.prop[1] := 1; > + > + mainw := TUIRowContainer.create(2); > + mainw.spacer := true; > + f.obj := mainw; > + > + if back then begin > + num_items := 4; > + end else begin > + num_items := 2; > + end; > + > + a := TUIMenu.create(num_items); > + with a do begin > + bgcolor := 0; > + color := 14; > + > + AddItem('Deutsch', nil); > + AddItem('US-Amerikanisch', nil); > + if back then begin > + AddItem('', nil); > + AddItem(Utf8Decode('Zur??ck'), nil); > + end; > + end; > + mainw[1] := a; > + mainw.fixed[1] := num_items; > + > + b := TUILabel.create; > + b.content := Utf8Decode('Bitte w??hle aus dem Men?? die richtige Tastaturbelegung aus.'); Vielleicht eher "gewünschte Tastaturbelegung"? (Man merkt nicht dass ich nichts zu kommentieren habe, oder? ;-)) > + mainw[0] := b; > + mainw.prop[0] := 30; > + > + a.selected := 0; > + repeat > + // Zeichnen > + screen.align(80, 24); > + screen.draw(1, 1); > + > + case readkey of > + #27: > + case ReadEscapeSequence of > + SK_UP: > + begin > + a.selected := (a.selected + num_items - 1) mod num_items; > + if a.selected = 2 then begin > + a.selected := 1; > + end; > + end; > + SK_DOWN: > + begin > + a.selected := (a.selected + 1) mod num_items; > + if a.selected = 2 then begin > + a.selected := 3; > + end; > + end; > + end; > + #10: > + case a.selected of > + 0: > + begin > + SetLayout('de'); > + break; > + end; > + 1: > + begin > + SetLayout('us'); > + break; > + end; > + 3: break; > + end; > + end; > + until false; > + > + f.obj := nil; > + mainw.free; > + screen.free; > +end; > + > +end. > diff --git a/src/modules/pas/setup/setup_lpt.pas b/src/modules/pas/setup/setup_lpt.pas > new file mode 100644 > index 0000000..e4207ab > --- /dev/null > +++ b/src/modules/pas/setup/setup_lpt.pas > @@ -0,0 +1,136 @@ > +unit setup_lpt; > + > +interface > + > +procedure SetupLPT(back: boolean); > + > +implementation > + > +uses sysutils, dos, tyndur, crt, tui; > + > +procedure SetRepo(repo: String); > +var > + cfg: text; > +begin > + Assign(cfg, 'file:/config/lpt/pkgsrc'); > + Rewrite(cfg); > + WriteLn(cfg, 'lpt ', repo); > + Close(cfg); > + > + TextBackground(0); > + TextColor(7); > + ClrScr; > + Exec('lpt', 'scan'); > + > + WriteLn; > + WriteLn('Bitte eine beliebige Taste dr??cken'); > + readkey; > +end; > + > +procedure SetupLPT(back: boolean); > +var > + mainw: TUIRowContainer; > + > + a: TUIMenu; > + b: TUILabel; > + > + buttons: TUIColContainer; > + btnOk: TUIButton; > + btnCancel: TUIButton; > + screen: TUIRowContainer; > + title: TUILabel; > + f: TUIFrame; > + num_items: integer; > +begin > + screen := TUIRowContainer.create(2); > + screen.bgcolor := 2; > + screen.color := 1; > + > + title := TUILabel.create; > + title.content := Utf8Decode('tyndur-Konfiguration: Quelle f??r lpt'); > + title.bgcolor := 1; > + title.color := 15; > + screen[0] := title; > + screen.fixed[0] := 1; > + > + f := TUIFrame.create(nil, 60, 12); > + screen[1] := f; > + screen.prop[1] := 1; > + > + mainw := TUIRowContainer.create(2); > + mainw.spacer := true; > + f.obj := mainw; > + > + if back then begin > + num_items := 4; > + end else begin > + num_items := 2; > + end; > + > + a := TUIMenu.create(num_items); > + with a do begin > + bgcolor := 0; > + color := 14; > + > + AddItem('Stabile Version (gothmog)', nil); > + AddItem('Entwicklerversion (current)', nil); > + if back then begin > + AddItem('', nil); > + AddItem(Utf8Decode('Zur??ck'), nil); > + end; > + end; > + mainw[1] := a; > + mainw.fixed[1] := num_items; > + > + b := TUILabel.create; > + b.content := Utf8Decode('Bitte w??hle aus dem Men?? die Quelle f??r lpt aus.'); > + mainw[0] := b; > + mainw.prop[0] := 30; > + > + a.selected := 0; > + repeat > + // Zeichnen > + screen.align(80, 24); > + screen.draw(1, 1); > + > + case readkey of > + #27: > + case ReadEscapeSequence of > + SK_UP: > + begin > + a.selected := (a.selected + num_items - 1) mod num_items; > + if a.selected = 2 then begin > + a.selected := 1; > + end; > + end; > + SK_DOWN: > + begin > + a.selected := (a.selected + 1) mod num_items; > + if a.selected = 2 then begin > + a.selected := 3; > + end; > + end; > + end; > + #10: > + case a.selected of > + 0: > + begin > + SetRepo('http://lpt.tyndur.org/gothmog/'); > + break; > + end; > + 1: > + begin > + SetRepo('http://lpt.tyndur.org/current/'); > + break; > + end; > + 3: break; > + end; > + end; > + until false; > + > + f.obj := nil; > + mainw.free; > + screen.free; > +end; > + > +end. Hm viel habe ich ja jetzt nicht gefunden. Das ganze sieht halt noch nach etwas viel Code-Duplikation aus, da könnte man wohl noch einiges vom UI-Code herausnehmen, aber jo, pack das von mir aus mal so rein, wenn es denn tut. ;-) Acked-by: Antoine Kaufmann <toni@xxxxxxxxxx> -- Antoine Kaufmann <toni@xxxxxxxxxxxxxxxx>
Attachment:
pgpbu1oEotPwd.pgp
Description: PGP signature