Compare commits

3 Commits

Author SHA1 Message Date
5c93f4e570 Progress bar at bottom 2025-09-30 00:28:29 +02:00
dfc3d4e579 Progress bar 2025-09-30 00:17:45 +02:00
e7b2683d2c Native compilation for windows 2025-09-25 12:23:59 +02:00
3 changed files with 56 additions and 4 deletions

View File

@@ -11,7 +11,10 @@
;; Native image (GraalVM)
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"};; Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
;; Protobuf for java
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}}
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
;; Progress bar
com.github.pmonks/spinner {:mvn/version "2.0.284"}
}
:aliases {;; Execute the app
:run {:main-opts ["-m" "totp.app"]}

33
native.cmd Normal file
View File

@@ -0,0 +1,33 @@
@echo off
setlocal
REM YOUR LOCAL GRAAL VM INSTALLATION
set JAVA_HOME=D:\programas\graalvm-jdk-21.0.7+8.1
REM generated file
set BIN_FILE=totp
set DEST_DIR=C:\Users\rubencj\util
set PATH=%JAVA_HOME%\bin;%CLOJURE_HOME%;%PATH%
set NATIVE=%JAVA_HOME%\bin\native-image.cmd
echo Using GraalVM native compiler: %NATIVE%
echo Creating uberjar
clojure -T:build uber
set UBERJAR=
for /f "delims=" %%a in ('dir /b /s target\clj-totp-*-standalone.jar') do @set UBERJAR=%%a
echo Created uberjar: %UBERJAR%
echo "Creating native image"
cmd /c %NATIVE% -jar %UBERJAR% -o target\%BIN_FILE% -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=reflect_config.json -H:-CheckToolchain
echo Executable created: target\%BIN_FILE%.exe
copy target\%BIN_FILE%.exe %DEST_DIR%
echo Native image copied to %DEST_DIR%\%BIN_FILE%.exe

View File

@@ -4,7 +4,8 @@
[totp.data :refer :all]
[cli-matic.core :refer [run-cmd]]
[clojure.pprint :as pp]
[clojure.string :as str])
[clojure.string :as str]
[progress.determinate :as pd])
(:import [java.util TimerTask Timer])
(:gen-class))
@@ -17,12 +18,27 @@
delay (int (- step-millis (rem now step-millis)))
fn-show (fn [s] (println (format "[%d] %s" (System/currentTimeMillis) (get-otp s algorithm digits period))))
task (proxy [TimerTask] []
(run [] (fn-show secret)))]
(run [] (fn-show secret)))
a (atom (int (- period (/ delay 1000))))
up-task (proxy [TimerTask] []
(run [] (pd/animate! a :opts {:total period
:style (:coloured-ascii-boxes pd/styles)
:label "Next TOTP"
:redraw-rate 1
;:line 1
}
;(println "inc" @a)
(if (< @a period)
(swap! a inc)
(reset! a 0)
))))]
(println "\n <Generating continuosly, press enter to stop>\n")
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
(println "Refresing in" (int (/ delay 1000)) "seconds")
(fn-show secret)
(. (new Timer) (scheduleAtFixedRate task delay step-millis)))
(. (new Timer) (scheduleAtFixedRate up-task 0 1000))
(. (new Timer) (scheduleAtFixedRate task delay step-millis))
)
(read-line))) ;; Waits for a key press