├── .github
├── dependabot.yml
├── release.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── .idea
├── $CACHE_FILE$
├── .gitignore
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── jarRepositories.xml
├── misc.xml
└── vcs.xml
├── LICENSE
├── README.md
├── build.gradle.kts
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle.kts
└── src
└── main
└── kotlin
├── dev
└── reimer
│ └── progressbar
│ └── ktx
│ └── ProgressBarExtensions.kt
└── me
└── tongfei
└── progressbar
└── InternalConsoleProgressBarConsumer.kt
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: gradle
4 | directory: /
5 | schedule:
6 | interval: weekly
7 | - package-ecosystem: github-actions
8 | directory: /
9 | schedule:
10 | interval: monthly
11 |
--------------------------------------------------------------------------------
/.github/release.yml:
--------------------------------------------------------------------------------
1 | changelog:
2 | exclude:
3 | labels:
4 | - ignore-for-release
5 | authors:
6 | - octocat
7 | categories:
8 | - title: "🪲 Bug Fixes"
9 | labels:
10 | - bug
11 | - title: "✨ New Features"
12 | labels:
13 | - enhancement
14 | - title: "📄 Other Changes"
15 | labels:
16 | - "*"
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: push
4 |
5 | jobs:
6 | gradle-build:
7 | name: 🏗️ Gradle build
8 | runs-on: ubuntu-latest
9 | steps:
10 | - name: 📥 Check-out
11 | uses: actions/checkout@v4
12 | - name: 🧰 Install JDK
13 | uses: actions/setup-java@v4
14 | with:
15 | java-version: 8
16 | distribution: temurin
17 | cache: gradle
18 | - name: 🏗️ Build with Gradle
19 | run: ./gradlew build
20 | gradle-test:
21 | name: ✅ Gradle test
22 | runs-on: ubuntu-latest
23 | steps:
24 | - name: 📥 Check-out
25 | uses: actions/checkout@v4
26 | - name: 🧰 Install JDK
27 | uses: actions/setup-java@v4
28 | with:
29 | java-version: 8
30 | distribution: temurin
31 | cache: gradle
32 | - name: ✅ Test with Gradle
33 | run: ./gradlew test
34 | github-release:
35 | name: 🚀 Create GitHub release
36 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
37 | needs:
38 | - gradle-build
39 | - gradle-test
40 | permissions:
41 | contents: write
42 | runs-on: ubuntu-latest
43 | steps:
44 | - name: 📥 Check-out
45 | uses: actions/checkout@v4
46 | - name: 🚀 Create GitHub release
47 | uses: softprops/action-gh-release@v2
48 | with:
49 | name: Release ${{ github.ref_name }}
50 | fail_on_unmatched_files: true
51 | draft: false
52 | prerelease: false
53 | generate_release_notes: true
54 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 |
3 | ### JetBrains template
4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
5 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
6 |
7 | # User-specific stuff
8 | .idea/**/workspace.xml
9 | .idea/**/tasks.xml
10 | .idea/**/dictionaries
11 | .idea/**/shelf
12 |
13 | # Sensitive or high-churn files
14 | .idea/**/dataSources/
15 | .idea/**/dataSources.ids
16 | .idea/**/dataSources.local.xml
17 | .idea/**/sqlDataSources.xml
18 | .idea/**/dynamic.xml
19 | .idea/**/uiDesigner.xml
20 | .idea/**/dbnavigator.xml
21 |
22 | # Gradle
23 | .idea/**/gradle.xml
24 | .idea/**/libraries
25 |
26 | # CMake
27 | cmake-build-debug/
28 | cmake-build-release/
29 |
30 | # Mongo Explorer plugin
31 | .idea/**/mongoSettings.xml
32 |
33 | # File-based project format
34 | *.iws
35 |
36 | # IntelliJ
37 | out/
38 |
39 | # mpeltonen/sbt-idea plugin
40 | .idea_modules/
41 |
42 | # JIRA plugin
43 | atlassian-ide-plugin.xml
44 |
45 | # Cursive Clojure plugin
46 | .idea/replstate.xml
47 |
48 | # Crashlytics plugin (for Android Studio and IntelliJ)
49 | com_crashlytics_export_strings.xml
50 | crashlytics.properties
51 | crashlytics-build.properties
52 | fabric.properties
53 |
54 | # Editor-based Rest Client
55 | .idea/httpRequests
56 |
57 | ### Android template
58 | # Built application files
59 | *.apk
60 | *.ap_
61 |
62 | # Files for the ART/Dalvik VM
63 | *.dex
64 |
65 | # Java class files
66 | *.class
67 |
68 | # Generated files
69 | bin/
70 | gen/
71 | out/
72 |
73 | # Gradle files
74 | .gradle/
75 | build/
76 |
77 | # Local configuration file (sdk path, etc)
78 | local.properties
79 |
80 | # Proguard folder generated by Eclipse
81 | proguard/
82 |
83 | # Log Files
84 | *.log
85 |
86 | # Android Studio Navigation editor temp files
87 | .navigation/
88 |
89 | # Android Studio captures folder
90 | captures/
91 |
92 | # IntelliJ
93 | *.iml
94 | .idea/workspace.xml
95 | .idea/tasks.xml
96 | .idea/gradle.xml
97 | .idea/assetWizardSettings.xml
98 | .idea/dictionaries
99 | .idea/libraries
100 | .idea/caches
101 |
102 | # Keystore files
103 | # Uncomment the following line if you do not want to check your keystore files in.
104 | #*.jks
105 |
106 | # External native build folder generated in Android Studio 2.2 and later
107 | .externalNativeBuild
108 |
109 | # Google Services (e.g. APIs or Firebase)
110 | google-services.json
111 |
112 | # Freeline
113 | freeline.py
114 | freeline/
115 | freeline_project_description.json
116 |
117 | # fastlane
118 | fastlane/report.xml
119 | fastlane/Preview.html
120 | fastlane/screenshots
121 | fastlane/test_output
122 | fastlane/readme.md
123 |
124 | ### Kotlin template
125 | # Compiled class file
126 | *.class
127 |
128 | # Log file
129 | *.log
130 |
131 | # BlueJ files
132 | *.ctxt
133 |
134 | # Mobile Tools for Java (J2ME)
135 | .mtj.tmp/
136 |
137 | # Package Files #
138 | *.jar
139 | *.war
140 | *.nar
141 | *.ear
142 | *.zip
143 | *.tar.gz
144 | *.rar
145 |
146 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
147 | hs_err_pid*
148 |
149 | ### Gradle template
150 | .gradle
151 | /build/
152 |
153 | # Ignore Gradle GUI config
154 | gradle-app.setting
155 |
156 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
157 | !gradle-wrapper.jar
158 |
159 | # Cache of project
160 | .gradletasknamecache
161 |
162 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
163 | # gradle/wrapper/gradle-wrapper.properties
--------------------------------------------------------------------------------
/.idea/$CACHE_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Jan Heinrich Reimer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/janheinrichmerker/progressbar-ktx/actions/workflows/ci.yml)
2 | [](https://jitpack.io/#dev.reimer/progressbar-ktx)
3 |
4 | # ⏳ progressbar-ktx[α](#status-α)
5 |
6 | Kotlin extensions for the [progressbar](https://github.com/ctongfei/progressbar) JVM library.
7 |
8 | ## Gradle Dependency
9 |
10 | This library is available on [**jitpack.io**](https://jitpack.io/#dev.reimer/progressbar-ktx).
11 | Add this in your `build.gradle.kts` or `build.gradle` file:
12 |
13 | Kotlin
14 |
15 | ```kotlin
16 | repositories {
17 | maven("https://jitpack.io")
18 | }
19 |
20 | dependencies {
21 | implementation("dev.reimer:progressbar-ktx:")
22 | }
23 | ```
24 |
25 |
26 |
27 | Groovy
28 |
29 | ```groovy
30 | repositories {
31 | maven { url 'https://jitpack.io' }
32 | }
33 |
34 | dependencies {
35 | implementation 'dev.reimer:progressbar-ktx:'
36 | }
37 | ```
38 |
39 |
40 |
41 | ## Status α
42 |
43 | ⚠️ _Warning:_ This project is in an experimental alpha stage:
44 | - The API may be changed at any time without further notice.
45 | - Development still happens on `master`.
46 | - Pull Requests are highly appreciated!
47 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "2.1.21"
3 | `maven-publish`
4 | id("org.jetbrains.dokka") version "0.9.17"
5 | id("com.palantir.git-version") version "3.2.0"
6 | }
7 |
8 | val gitVersion: groovy.lang.Closure by extra
9 | group = "dev.reimer"
10 | version = gitVersion()
11 |
12 | repositories {
13 | mavenCentral()
14 | }
15 |
16 | dependencies {
17 | implementation(kotlin("stdlib"))
18 | implementation("me.tongfei:progressbar:0.8.1")
19 | }
20 |
21 | lateinit var javadocJar: TaskProvider
22 | lateinit var sourcesJar: TaskProvider
23 |
24 | tasks {
25 | test {
26 | useJUnitPlatform()
27 | }
28 |
29 | // Include project license in generated JARs.
30 | withType {
31 | from(project.projectDir) {
32 | include("LICENSE")
33 | into("META-INF")
34 | }
35 | }
36 |
37 | // Generate Kotlin/Java documentation from sources.
38 | dokka {
39 | outputFormat = "html"
40 | }
41 |
42 | // JAR containing Kotlin/Java documentation.
43 | javadocJar = register("javadocJar") {
44 | group = JavaBasePlugin.DOCUMENTATION_GROUP
45 | dependsOn(dokka)
46 | from(dokka)
47 | archiveClassifier.set("javadoc")
48 | }
49 |
50 | // JAR containing all source files.
51 | sourcesJar = register("sourcesJar") {
52 | from(sourceSets.main.get().allSource)
53 | archiveClassifier.set("sources")
54 | }
55 | }
56 |
57 | publishing {
58 | publications {
59 | create("maven") {
60 | from(components["java"])
61 | artifact(sourcesJar.get())
62 | artifact(javadocJar.get())
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/janheinrichmerker/progressbar-ktx/4671faa1ae4098ca2a0f92a910dede006df005ce/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88 |
89 | # Use the maximum available, or set MAX_FD != -1 to use that value.
90 | MAX_FD=maximum
91 |
92 | warn () {
93 | echo "$*"
94 | } >&2
95 |
96 | die () {
97 | echo
98 | echo "$*"
99 | echo
100 | exit 1
101 | } >&2
102 |
103 | # OS specific support (must be 'true' or 'false').
104 | cygwin=false
105 | msys=false
106 | darwin=false
107 | nonstop=false
108 | case "$( uname )" in #(
109 | CYGWIN* ) cygwin=true ;; #(
110 | Darwin* ) darwin=true ;; #(
111 | MSYS* | MINGW* ) msys=true ;; #(
112 | NONSTOP* ) nonstop=true ;;
113 | esac
114 |
115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116 |
117 |
118 | # Determine the Java command to use to start the JVM.
119 | if [ -n "$JAVA_HOME" ] ; then
120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121 | # IBM's JDK on AIX uses strange locations for the executables
122 | JAVACMD=$JAVA_HOME/jre/sh/java
123 | else
124 | JAVACMD=$JAVA_HOME/bin/java
125 | fi
126 | if [ ! -x "$JAVACMD" ] ; then
127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128 |
129 | Please set the JAVA_HOME variable in your environment to match the
130 | location of your Java installation."
131 | fi
132 | else
133 | JAVACMD=java
134 | if ! command -v java >/dev/null 2>&1
135 | then
136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 | fi
142 |
143 | # Increase the maximum file descriptors if we can.
144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145 | case $MAX_FD in #(
146 | max*)
147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148 | # shellcheck disable=SC2039,SC3045
149 | MAX_FD=$( ulimit -H -n ) ||
150 | warn "Could not query maximum file descriptor limit"
151 | esac
152 | case $MAX_FD in #(
153 | '' | soft) :;; #(
154 | *)
155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156 | # shellcheck disable=SC2039,SC3045
157 | ulimit -n "$MAX_FD" ||
158 | warn "Could not set maximum file descriptor limit to $MAX_FD"
159 | esac
160 | fi
161 |
162 | # Collect all arguments for the java command, stacking in reverse order:
163 | # * args from the command line
164 | # * the main class name
165 | # * -classpath
166 | # * -D...appname settings
167 | # * --module-path (only if needed)
168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169 |
170 | # For Cygwin or MSYS, switch paths to Windows format before running java
171 | if "$cygwin" || "$msys" ; then
172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174 |
175 | JAVACMD=$( cygpath --unix "$JAVACMD" )
176 |
177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
178 | for arg do
179 | if
180 | case $arg in #(
181 | -*) false ;; # don't mess with options #(
182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183 | [ -e "$t" ] ;; #(
184 | *) false ;;
185 | esac
186 | then
187 | arg=$( cygpath --path --ignore --mixed "$arg" )
188 | fi
189 | # Roll the args list around exactly as many times as the number of
190 | # args, so each arg winds up back in the position where it started, but
191 | # possibly modified.
192 | #
193 | # NB: a `for` loop captures its iteration list before it begins, so
194 | # changing the positional parameters here affects neither the number of
195 | # iterations, nor the values presented in `arg`.
196 | shift # remove old arg
197 | set -- "$@" "$arg" # push replacement arg
198 | done
199 | fi
200 |
201 |
202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204 |
205 | # Collect all arguments for the java command:
206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207 | # and any embedded shellness will be escaped.
208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209 | # treated as '${Hostname}' itself on the command line.
210 |
211 | set -- \
212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
213 | -classpath "$CLASSPATH" \
214 | org.gradle.wrapper.GradleWrapperMain \
215 | "$@"
216 |
217 | # Stop when "xargs" is not available.
218 | if ! command -v xargs >/dev/null 2>&1
219 | then
220 | die "xargs is not available"
221 | fi
222 |
223 | # Use "xargs" to parse quoted args.
224 | #
225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226 | #
227 | # In Bash we could simply go:
228 | #
229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230 | # set -- "${ARGS[@]}" "$@"
231 | #
232 | # but POSIX shell has neither arrays nor command substitution, so instead we
233 | # post-process each arg (as a line of input to sed) to backslash-escape any
234 | # character that might be a shell metacharacter, then use eval to reverse
235 | # that process (while maintaining the separation between arguments), and wrap
236 | # the whole thing up as a single "set" statement.
237 | #
238 | # This will of course break if any of these variables contains a newline or
239 | # an unmatched quote.
240 | #
241 |
242 | eval "set -- $(
243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244 | xargs -n1 |
245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246 | tr '\n' ' '
247 | )" '"$@"'
248 |
249 | exec "$JAVACMD" "$@"
250 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo. 1>&2
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48 | echo. 1>&2
49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50 | echo location of your Java installation. 1>&2
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo. 1>&2
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62 | echo. 1>&2
63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64 | echo location of your Java installation. 1>&2
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "progressbar-ktx"
2 |
3 |
--------------------------------------------------------------------------------
/src/main/kotlin/dev/reimer/progressbar/ktx/ProgressBarExtensions.kt:
--------------------------------------------------------------------------------
1 | package dev.reimer.progressbar.ktx
2 |
3 | import me.tongfei.progressbar.*
4 | import java.io.InputStream
5 | import java.io.PrintStream
6 | import java.text.DecimalFormat
7 | import java.util.*
8 | import java.util.stream.BaseStream
9 | import java.util.stream.Stream
10 | import kotlin.time.Duration
11 | import kotlin.time.DurationUnit
12 | import kotlin.time.ExperimentalTime
13 | import kotlin.time.toDuration
14 |
15 | @DslMarker
16 | annotation class ProgressBarDsl
17 |
18 | @ProgressBarDsl
19 | class ProgressBarBuilderScope {
20 |
21 | private companion object {
22 | private val defaultDecimalFormat = DecimalFormat("#.0")
23 | private val emptyDecimalFormat = DecimalFormat()
24 | }
25 |
26 | var task: String = ""
27 | var initialMax: Long = -1
28 | var updateIntervalMillis: Int = 1000
29 | @ExperimentalTime
30 | var updateInterval: Duration
31 | get() = updateIntervalMillis.toDuration(DurationUnit.MILLISECONDS)
32 | set(value) {
33 | updateIntervalMillis = value.inWholeMilliseconds.toInt()
34 | }
35 | var style: ProgressBarStyle = ProgressBarStyle.COLORFUL_UNICODE_BLOCK
36 | var consumer: ProgressBarConsumer = InternalConsoleProgressBarConsumer()
37 | var out: PrintStream
38 | get() {
39 | return consumer.let { consumer ->
40 | check(consumer is InternalConsoleProgressBarConsumer) {
41 | "Cannot get print stream from custom consumer."
42 | }
43 | consumer.out
44 | }
45 | }
46 | set(value) {
47 | consumer = InternalConsoleProgressBarConsumer(value)
48 | }
49 | var unitName: String = ""
50 | var unitSize: Long = 1
51 | var showSpeed: Boolean
52 | get() = speedFormat !== emptyDecimalFormat
53 | set(value) {
54 | speedFormat = when {
55 | value && speedFormat === emptyDecimalFormat -> defaultDecimalFormat
56 | else -> emptyDecimalFormat
57 | }
58 | }
59 | var speedFormat: DecimalFormat = emptyDecimalFormat
60 |
61 | fun unit(unitName: String, unitSize: Long) {
62 | this.unitName = unitName
63 | this.unitSize = unitSize
64 | }
65 |
66 | fun showSpeed(speedFormat: DecimalFormat?) {
67 | showSpeed = true
68 | this.speedFormat = speedFormat!!
69 | }
70 |
71 | internal fun builder(): ProgressBarBuilder {
72 | val builder = ProgressBarBuilder()
73 | .setTaskName(task)
74 | .setInitialMax(initialMax)
75 | .setUpdateIntervalMillis(updateIntervalMillis)
76 | .setStyle(style)
77 | .setConsumer(consumer)
78 | .setUnit(unitName, unitSize)
79 | if (showSpeed) {
80 | builder.showSpeed(speedFormat)
81 | }
82 | return builder
83 | }
84 |
85 | private fun buildWithConsumer(consumer: ProgressBarConsumer? = null): ProgressBar {
86 | val builder = ProgressBarBuilder()
87 | .setTaskName(task)
88 | .setInitialMax(initialMax)
89 | .setUpdateIntervalMillis(updateIntervalMillis)
90 | .setStyle(style)
91 | .setInitialMax(initialMax)
92 | if (consumer != null) {
93 | builder.setConsumer(consumer)
94 | }
95 | return builder.build()
96 | }
97 |
98 | private fun buildWithStream(printStream: PrintStream): ProgressBar {
99 | return ProgressBar(
100 | task,
101 | initialMax,
102 | updateIntervalMillis,
103 | printStream,
104 | style,
105 | unitName,
106 | unitSize,
107 | showSpeed,
108 | speedFormat
109 | )
110 | }
111 | }
112 |
113 | private fun progressBarBuilder(configure: ProgressBarBuilderScope.() -> Unit) =
114 | ProgressBarBuilderScope().apply(configure).builder()
115 |
116 | fun progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): ProgressBar = progressBarBuilder(configure).build()
117 |
118 | @JvmName("progressBarImmutable")
119 | fun Iterator.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): Iterator =
120 | ProgressBar.wrap(this, progressBarBuilder(configure))
121 |
122 | fun MutableIterator.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): MutableIterator =
123 | ProgressBar.wrap(this, progressBarBuilder(configure))
124 |
125 | @JvmName("progressBarImmutable")
126 | fun Iterable.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): Iterable =
127 | ProgressBar.wrap(this, progressBarBuilder(configure))
128 |
129 | fun MutableIterable.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): MutableIterable =
130 | ProgressBar.wrap(this, progressBarBuilder(configure))
131 |
132 | fun InputStream.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): InputStream =
133 | ProgressBar.wrap(this, progressBarBuilder(configure))
134 |
135 | fun Spliterator.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): Spliterator =
136 | ProgressBar.wrap(this, progressBarBuilder(configure))
137 |
138 | fun > S.progressBar(configure: ProgressBarBuilderScope.() -> Unit = {}): Stream =
139 | ProgressBar.wrap(this, progressBarBuilder(configure))
140 |
141 |
142 |
--------------------------------------------------------------------------------
/src/main/kotlin/me/tongfei/progressbar/InternalConsoleProgressBarConsumer.kt:
--------------------------------------------------------------------------------
1 | package me.tongfei.progressbar
2 |
3 | import java.io.PrintStream
4 |
5 | internal class InternalConsoleProgressBarConsumer(
6 | internal val out: PrintStream = defaultOut
7 | ) : ConsoleProgressBarConsumer(out) {
8 | private companion object {
9 | private val defaultOut: PrintStream = System.err
10 | }
11 | }
12 |
--------------------------------------------------------------------------------