Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip version 3 #1

Merged
merged 4 commits into from Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,60 @@
# Clojure CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
#
version: 2.1
jobs:
jvm:
docker:
# specify the version you desire here
- image: circleci/clojure:lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
BABASHKA_PLATFORM: linux # could be used in jar name
resource_class: large
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Install Clojure
command: |
wget -nc https://download.clojure.org/install/linux-install-1.10.1.447.sh
chmod +x linux-install-1.10.1.447.sh
sudo ./linux-install-1.10.1.447.sh

deploy:
resource_class: large
docker:
- image: circleci/clojure:lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: .circleci/script/deploy
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}

workflows:
version: 2
ci:
jobs:
- jvm
- deploy:
filters:
branches:
only: master
requires:
- jvm
8 changes: 8 additions & 0 deletions .circleci/script/deploy
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]
then
lein deploy clojars
fi

exit 0;
13 changes: 6 additions & 7 deletions project.clj
@@ -1,12 +1,11 @@
(defproject clojure-lanterna "0.9.7"
(defproject babashka/clojure-lanterna "0.9.8-SNAPSHOT"
:description "A Clojure wrapper around the Lanterna terminal output library."
:url "http://multimud.github.io/clojure-lanterna/"
:url "https://github.com/babashka/clojure-lanterna"
:license {:name "LGPL"}
:dependencies [[org.clojure/clojure "1.4.0"]
[com.googlecode.lanterna/lanterna "2.1.7"]]
:dependencies [[com.googlecode.lanterna/lanterna "3.0.3"]]
:java-source-paths ["./java"]
; :repositories {"sonatype-snapshots" "https://oss.sonatype.org/content/repositories/snapshots"}
:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.2-alpha1"]]}}
:repositories {"releases" {:url "https://clojars.org/repo"
:username :env
:password :env
:username :env/babashka_nrepl_clojars_user
:password :env/babashka_nrepl_clojars_pass
:sign-releases false}})
Empty file removed src/README.markdown
Empty file.
4 changes: 2 additions & 2 deletions src/lanterna/common.clj
@@ -1,9 +1,9 @@
(ns lanterna.common
(:import com.googlecode.lanterna.input.Key)
(:import com.googlecode.lanterna.input.KeyType)
(:require [lanterna.constants :as c]))


(defn parse-key [^Key k]
(defn parse-key [^KeyType k]
(when k
(let [kind (c/key-codes (.getKind k))]
(if (= kind :normal)
Expand Down
104 changes: 41 additions & 63 deletions src/lanterna/constants.clj
@@ -1,72 +1,50 @@
(ns lanterna.constants
(:import java.nio.charset.Charset
com.googlecode.lanterna.TerminalFacade
com.googlecode.lanterna.screen.Screen
com.googlecode.lanterna.terminal.Terminal
com.googlecode.lanterna.screen.ScreenCharacterStyle
com.googlecode.lanterna.terminal.swing.TerminalPalette
com.googlecode.lanterna.input.Key))

(:import com.googlecode.lanterna.SGR
com.googlecode.lanterna.TextColor$ANSI
com.googlecode.lanterna.input.KeyType
java.nio.charset.Charset))

(def charsets {:utf-8 (Charset/forName "UTF-8")})

(def colors
{:black com.googlecode.lanterna.terminal.Terminal$Color/BLACK
:white com.googlecode.lanterna.terminal.Terminal$Color/WHITE
:red com.googlecode.lanterna.terminal.Terminal$Color/RED
:green com.googlecode.lanterna.terminal.Terminal$Color/GREEN
:blue com.googlecode.lanterna.terminal.Terminal$Color/BLUE
:cyan com.googlecode.lanterna.terminal.Terminal$Color/CYAN
:magenta com.googlecode.lanterna.terminal.Terminal$Color/MAGENTA
:yellow com.googlecode.lanterna.terminal.Terminal$Color/YELLOW
:default com.googlecode.lanterna.terminal.Terminal$Color/DEFAULT})
{:black TextColor$ANSI/BLACK
:white TextColor$ANSI/WHITE
:red TextColor$ANSI/RED
:green TextColor$ANSI/GREEN
:blue TextColor$ANSI/BLUE
:cyan TextColor$ANSI/CYAN
:magenta TextColor$ANSI/MAGENTA
:yellow TextColor$ANSI/YELLOW
:default TextColor$ANSI/DEFAULT})

(def styles
{:bold ScreenCharacterStyle/Bold
:reverse ScreenCharacterStyle/Reverse
:underline ScreenCharacterStyle/Underline
:blinking ScreenCharacterStyle/Blinking})
{:bold SGR/BOLD
:reverse SGR/REVERSE
:underline SGR/UNDERLINE
:blinking SGR/BLINK})

(def key-codes
{com.googlecode.lanterna.input.Key$Kind/NormalKey :normal
com.googlecode.lanterna.input.Key$Kind/Escape :escape
com.googlecode.lanterna.input.Key$Kind/Backspace :backspace
com.googlecode.lanterna.input.Key$Kind/ArrowLeft :left
com.googlecode.lanterna.input.Key$Kind/ArrowRight :right
com.googlecode.lanterna.input.Key$Kind/ArrowUp :up
com.googlecode.lanterna.input.Key$Kind/ArrowDown :down
com.googlecode.lanterna.input.Key$Kind/Insert :insert
com.googlecode.lanterna.input.Key$Kind/Delete :delete
com.googlecode.lanterna.input.Key$Kind/Home :home
com.googlecode.lanterna.input.Key$Kind/End :end
com.googlecode.lanterna.input.Key$Kind/PageUp :page-up
com.googlecode.lanterna.input.Key$Kind/PageDown :page-down
com.googlecode.lanterna.input.Key$Kind/Tab :tab
com.googlecode.lanterna.input.Key$Kind/ReverseTab :reverse-tab
com.googlecode.lanterna.input.Key$Kind/Enter :enter
com.googlecode.lanterna.input.Key$Kind/Unknown :unknown
com.googlecode.lanterna.input.Key$Kind/CursorLocation :cursor-location})


(def palettes
{:gnome TerminalPalette/GNOME_TERMINAL
:vga TerminalPalette/STANDARD_VGA
:windows-xp TerminalPalette/WINDOWS_XP_COMMAND_PROMPT
:mac-os-x TerminalPalette/MAC_OS_X_TERMINAL_APP
:xterm TerminalPalette/PUTTY
:putty TerminalPalette/XTERM})

(def enter-styles
{:bold com.googlecode.lanterna.terminal.Terminal$SGR/ENTER_BOLD
:reverse com.googlecode.lanterna.terminal.Terminal$SGR/ENTER_REVERSE
:blinking com.googlecode.lanterna.terminal.Terminal$SGR/ENTER_BLINK
:underline com.googlecode.lanterna.terminal.Terminal$SGR/ENTER_UNDERLINE})

(def exit-styles
{:bold com.googlecode.lanterna.terminal.Terminal$SGR/EXIT_BOLD
:reverse com.googlecode.lanterna.terminal.Terminal$SGR/EXIT_REVERSE
:blinking com.googlecode.lanterna.terminal.Terminal$SGR/EXIT_BLINK
:underline com.googlecode.lanterna.terminal.Terminal$SGR/EXIT_UNDERLINE})

(def reset-style
com.googlecode.lanterna.terminal.Terminal$SGR/RESET_ALL)
{;; KeyType/NormalKey :normal
KeyType/Escape :escape
KeyType/Backspace :backspace
KeyType/ArrowLeft :left
KeyType/ArrowRight :right
KeyType/ArrowUp :up
KeyType/ArrowDown :down
KeyType/Insert :insert
KeyType/Delete :delete
KeyType/Home :home
KeyType/End :end
KeyType/PageUp :page-up
KeyType/PageDown :page-down
KeyType/Tab :tab
KeyType/ReverseTab :reverse-tab
KeyType/Enter :enter
KeyType/Unknown :unknown
KeyType/CursorLocation :cursor-location})

(def sgr
{:bold com.googlecode.lanterna.SGR/BOLD
:reverse com.googlecode.lanterna.SGR/REVERSE
:blinking com.googlecode.lanterna.SGR/BLINK
:underline com.googlecode.lanterna.SGR/UNDERLINE})
87 changes: 13 additions & 74 deletions src/lanterna/screen.clj
@@ -1,14 +1,19 @@
(ns lanterna.screen
(:import com.googlecode.lanterna.screen.Screen
com.googlecode.lanterna.terminal.Terminal)
(:use [lanterna.common :only [parse-key block-on]])
(:require [lanterna.constants :as c]
[lanterna.terminal :as t]))


(defn enumerate [s]
(:import
com.googlecode.lanterna.screen.Screen
com.googlecode.lanterna.terminal.Terminal
com.googlecode.lanterna.screen.TerminalScreen)
(:require
[lanterna.common :refer [parse-key block-on]]
[lanterna.constants :as c]
[lanterna.terminal :as t]))

(defn- enumerate [s]
(map vector (iterate inc 0) s))

(defn ^Screen terminal-screen [^Terminal terminal]
(TerminalScreen. terminal))

(defn add-resize-listener
"Create a listener that will call the supplied fn when the screen is resized.

Expand All @@ -28,56 +33,6 @@
[^Screen screen listener]
(t/remove-resize-listener (.getTerminal screen) listener))

(defn get-screen
"Get a screen object.

kind can be one of the following:

:auto - Try to guess the right type of screen based on OS, whether
there's a windowing environment, etc
:swing - Force a Swing-based screen.
:text - Force a console (i.e.: non-Swing) screen. Try to guess the
appropriate kind of console (UNIX/Cygwin) by the OS.
:unix - Force a UNIX console screen.
:cygwin - Force a Cygwin console screen.

Options can contain one or more of the following keys:

:cols - Width of the desired screen in characters (default 80).
:rows - Height of the desired screen in characters (default 24).
:charset - Charset of the desired screen. Can be any of
(keys lanterna.constants/charsets) (default :utf-8).
:resize-listener - A function to call when the screen is resized. This
function should take two parameters: the new number of
columns, and the new number of rows.
:font - Font to use. String or sequence of strings.
Use (lanterna.terminal/get-available-fonts) to see your options.
Will fall back to a basic monospaced font if none of the given
names are available.
:font-size - An int of the size of the font to use.

NOTE: The options are really just a suggestion!

The console screen will ignore rows and columns and will be the size of the
user's window.

The Swing screen will start out at this size but can be resized later by the
user, and will ignore the charset entirely.

God only know what Cygwin will do.

"
([] (get-screen :auto {}))
([kind] (get-screen kind {}))
([kind {:as opts
:keys [cols rows charset resize-listener]
:or {cols 80
rows 24
charset :utf-8
resize-listener nil}}]
(new Screen (t/get-terminal kind opts))))


(defn start
"Start the screen. Consider using in-screen instead.

Expand Down Expand Up @@ -299,19 +254,3 @@
([^Screen screen] (get-key-blocking screen {}))
([^Screen screen {:keys [interval timeout] :as opts}]
(block-on get-key [screen] opts)))


(comment
(def s (get-screen))
(start s)

(put-sheet s 5 5 ["foo" "bar" "hello"])
(put-sheet s 5 9 [[\f \o \o] ["b" "a" "r"] "hello"])
(let [r [\r {:bg :red :fg :white}]
g [\g {:bg :green :fg :black}]
b [\b {:bg :blue :fg :white}]]
(put-sheet s 5 13 [[r r r] [g g g] [b b b]]))

(redraw s)
(stop s)
)