Created
April 12, 2014 01:39
-
-
Save mtcomb/10514137 to your computer and use it in GitHub Desktop.
Using lanterna (https://code.google.com/p/lanterna/) from clojure directly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns lant.ActionListTest) | |
; lanterna/src/test/java/com/googlecode/lanterna/test/gui/ActionListTest.java | |
(import 'com.googlecode.lanterna.gui.Action) | |
(import 'com.googlecode.lanterna.gui.Border) | |
(import 'com.googlecode.lanterna.gui.Border$Invisible) | |
(import 'com.googlecode.lanterna.gui.GUIScreen) | |
(import 'com.googlecode.lanterna.gui.GUIScreen$Position) | |
(import 'com.googlecode.lanterna.gui.Window) | |
(import 'com.googlecode.lanterna.gui.component.ActionListBox) | |
(import 'com.googlecode.lanterna.gui.component.Button) | |
(import 'com.googlecode.lanterna.gui.component.EmptySpace) | |
(import 'com.googlecode.lanterna.gui.component.Panel) | |
(import 'com.googlecode.lanterna.gui.component.Panel$Orientation) | |
(import 'com.googlecode.lanterna.gui.dialog.MessageBox) | |
(import 'com.googlecode.lanterna.gui.layout.LayoutParameter) | |
(import 'com.googlecode.lanterna.TerminalFacade) | |
(defn ActionListBoxItem [window nr] | |
(let [item (proxy [Action] [] | |
(toString [] (str "ActionListBox item #" nr)) | |
(doAction [] | |
(MessageBox/showMessageBox | |
(.getOwner window) | |
"Action" (str "Selected " (.toString this)))))] | |
item)) | |
(defn ActionListTest [] | |
(let [window1 (Window. "Text box window") | |
mainPanel (Panel. (Border$Invisible.) (Panel$Orientation/VERTICAL)) | |
actionListBox (ActionListBox.) | |
buttonPanel (Panel. (Border$Invisible.) (Panel$Orientation/HORIZONTAL)) | |
exitButton (Button. "Exit" | |
(reify Action (doAction [this] (.close window1)))) | |
layout (into-array #^LayoutParameter [(LayoutParameter. "")])] | |
(doseq [i (range 5)] | |
(. actionListBox addAction (ActionListBoxItem window1 (inc i)))) | |
(. mainPanel addComponent actionListBox layout) | |
(. window1 addComponent mainPanel layout) | |
(. buttonPanel addComponent (EmptySpace. 20 1) layout) | |
(. buttonPanel addComponent exitButton layout) | |
(. window1 addComponent buttonPanel layout) | |
window1)) | |
(defn -main [& args] | |
(let [guiScreen (TerminalFacade/createGUIScreen | |
(TerminalFacade/createScreen | |
(TerminalFacade/createTerminal)))] | |
(. (.getScreen guiScreen) startScreen) | |
(. guiScreen showWindow (ActionListTest) GUIScreen$Position/CENTER) | |
(. (.getScreen guiScreen) stopScreen) | |
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns lant.MultiWindowTest) | |
; lanterna/src/test/java/com/googlecode/lanterna/test/gui/MultiWindowTest.java | |
(import 'com.googlecode.lanterna.gui.Action) | |
(import 'com.googlecode.lanterna.gui.GUIScreen) | |
(import 'com.googlecode.lanterna.gui.Window) | |
(import 'com.googlecode.lanterna.gui.component.Button) | |
(import 'com.googlecode.lanterna.gui.dialog.MessageBox) | |
(import 'com.googlecode.lanterna.gui.layout.LayoutParameter) | |
(import 'com.googlecode.lanterna.gui.layout.LinearLayout) | |
(import 'com.googlecode.lanterna.TerminalFacade) | |
(defn MyWindow [] | |
(let [myWindow (Window. "My Window!") | |
layout (into-array #^LayoutParameter [(LayoutParameter. "")])] | |
(doto myWindow | |
(.addComponent (Button. "Button with no action") layout) | |
(.addComponent (Button. "Button with action" | |
(reify Action (doAction [this] | |
(MessageBox/showMessageBox (.getOwner myWindow) | |
"Hello" "You selected the button with an action attached to it!")))) layout) | |
(.addComponent (Button. "MessageBox close" | |
(reify Action (doAction [this] | |
(MessageBox/showMessageBox (.getOwner myWindow) | |
"Information" | |
"When you close this dialog, the owner window will close too") | |
(.close myWindow)))) layout) | |
(.addComponent (Button. "New window" | |
(reify Action (doAction [this] | |
(.showWindow (.getOwner myWindow) (MyWindow))))) layout) | |
(.addComponent (Button. "Close window" | |
(reify Action (doAction [this] (.close myWindow)))) layout) | |
) | |
)) | |
(defn -main [& args] | |
(let [guiScreen (TerminalFacade/createGUIScreen | |
(TerminalFacade/createScreen | |
(TerminalFacade/createTerminal)))] | |
; (TerminalFacade/createTextTerminal)))] ; doesn't work! | |
(.startScreen (.getScreen guiScreen)) | |
(.showWindow guiScreen (MyWindow)) | |
(.stopScreen (.getScreen guiScreen)) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment