-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7acdf74
Showing
19 changed files
with
796 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc | ||
TODO.md |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Vasilii Ianguzin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
MAKEFLAGS += --no-print-directory | ||
EXECUTABLE_NAME := progressline | ||
SWIFT_VERSION := 5.10 | ||
ROOT_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
DOCKER_RUN := docker run --rm --volume $(ROOT_PATH):/workdir --workdir /workdir | ||
ZIP := zip -j | ||
BUILD_FLAGS = --disable-sandbox --configuration release --triple $(TRIPLE) | ||
ifeq ($(TRIPLE), aarch64-unknown-linux-gnu) | ||
BUILD_FLAGS := $(BUILD_FLAGS) --static-swift-stdlib | ||
SWIFT := $(DOCKER_RUN) --platform linux/arm64 swift:$(SWIFT_VERSION) swift | ||
STRIP := $(DOCKER_RUN) --platform linux/arm64 swift:$(SWIFT_VERSION) strip -s | ||
else ifeq ($(TRIPLE), x86_64-unknown-linux-gnu) | ||
BUILD_FLAGS := $(BUILD_FLAGS) --static-swift-stdlib | ||
SWIFT := $(DOCKER_RUN) --platform linux/amd64 swift:$(SWIFT_VERSION) swift | ||
STRIP := $(DOCKER_RUN) --platform linux/amd64 swift:$(SWIFT_VERSION) strip -s | ||
else | ||
SWIFT := swift | ||
STRIP := strip -rSTx | ||
endif | ||
EXECUTABLE_PATH = $(shell swift build $(BUILD_FLAGS) --show-bin-path)/$(EXECUTABLE_NAME) | ||
EXECUTABLE_ARCHIVE_PATH = .build/artifacts/$(EXECUTABLE_NAME)-$(TRIPLE).zip | ||
|
||
clean: | ||
@rm -rf .build 2> /dev/null || true | ||
.PHONY: clean | ||
|
||
prepare_release_artifacts: \ | ||
prepare_release_artifacts_linux_arm64 \ | ||
prepare_release_artifacts_linux_x86_64 \ | ||
prepare_release_artifacts_macos_arm64 \ | ||
prepare_release_artifacts_macos_x86_64 | ||
.PHONY: prepare_release_artifacts | ||
|
||
prepare_release_artifacts_linux_arm64: | ||
@$(MAKE) prepare_release_artifacts_for_triple TRIPLE=aarch64-unknown-linux-gnu | ||
.PHONY: prepare_release_artifacts_linux_arm64 | ||
|
||
prepare_release_artifacts_linux_x86_64: | ||
@$(MAKE) prepare_release_artifacts_for_triple TRIPLE=x86_64-unknown-linux-gnu | ||
.PHONY: prepare_release_artifacts_linux_x86_64 | ||
|
||
prepare_release_artifacts_macos_arm64: | ||
@$(MAKE) prepare_release_artifacts_for_triple TRIPLE=arm64-apple-macosx | ||
.PHONY: prepare_release_artifacts_macos_arm64 | ||
|
||
prepare_release_artifacts_macos_x86_64: | ||
@$(MAKE) prepare_release_artifacts_for_triple TRIPLE=x86_64-apple-macosx | ||
.PHONY: prepare_release_artifacts_macos_x86_64 | ||
|
||
define relpath | ||
$(shell \ | ||
base="$(1)"; \ | ||
abs="$(2)"; \ | ||
common_part="$$base"; \ | ||
back=""; \ | ||
while [ "$${abs#$$common_part}" = "$$abs" ]; do \ | ||
common_part=$$(dirname "$$common_part"); \ | ||
if [ -z "$$back" ]; then \ | ||
back=".."; \ | ||
else \ | ||
back="../$$back"; \ | ||
fi; \ | ||
done; \ | ||
if [ "$$common_part" = "/" ]; then \ | ||
rel="$$back$${abs#/}"; \ | ||
else \ | ||
forward="$${abs#$$common_part/}"; \ | ||
rel="$$back$$forward"; \ | ||
fi; \ | ||
echo "$$rel" \ | ||
) | ||
endef | ||
|
||
# use relative path for use with docker container | ||
RELATIVE_EXECUTABLE_PATH = $(call relpath,$(ROOT_PATH),$(EXECUTABLE_PATH)) | ||
GREEN := \033[0;32m | ||
NC := \033[0m | ||
|
||
prepare_release_artifacts_for_triple: | ||
$(SWIFT) build $(BUILD_FLAGS) 1> /dev/null | ||
$(STRIP) $(RELATIVE_EXECUTABLE_PATH) | ||
@echo "$(GREEN)Built $(EXECUTABLE_PATH)$(NC)" | ||
zip -j $(EXECUTABLE_ARCHIVE_PATH) $(EXECUTABLE_PATH) | ||
@echo "$(GREEN)Archived $(EXECUTABLE_ARCHIVE_PATH)$(NC)" | ||
.PHONY: prepare_release_artifacts_for_triple |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"originHash" : "e759c45271facbb3650829c703702a2ac4817adf75a8116cc3d77eae8e3d3bae", | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser.git", | ||
"state" : { | ||
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", | ||
"version" : "1.4.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-concurrency-extras", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-concurrency-extras.git", | ||
"state" : { | ||
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71", | ||
"version" : "1.1.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-tagged", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-tagged.git", | ||
"state" : { | ||
"revision" : "3907a9438f5b57d317001dc99f3f11b46882272b", | ||
"version" : "0.10.0" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// swift-tools-version: 5.10 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ProgressLine", | ||
platforms: [ | ||
.macOS(.v10_15), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"), | ||
.package(url: "https://github.com/pointfreeco/swift-tagged.git", from: "0.10.0"), | ||
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras.git", from: "1.1.0"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "progressline", | ||
dependencies: [ | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
.product(name: "TaggedTime", package: "swift-tagged"), | ||
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"), | ||
], swiftSettings: [ | ||
.enableExperimentalFeature("StrictConcurrency"), | ||
] | ||
), | ||
] | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
**ProgressLine** is a command-line tool for tracking the progress of piped commands in a compact one-line format. | ||
|
||
 | ||
|
||
## Overview | ||
|
||
ProgressLine enhances your command-line experience by providing a visually appealing way to monitor the progress of long-running tasks. It integrates seamlessly into your existing workflow, allowing you to focus on your work while staying informed about the progress. | ||
|
||
## Usage | ||
|
||
Simply pipe your command output into `progressline` to start tracking: | ||
|
||
```sh | ||
long-running-command | progressline | ||
``` | ||
|
||
If the command you are executing also writes data to `stderr`, then you should probably use ["redirection"](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) and send `stderr` messages to `stdout` so that they also go through the `progressline`: | ||
|
||
``` sh | ||
long-running-command 2>&1 | progressline | ||
``` | ||
|
||
**ProgressLine** offers different styles to represent activity, they can be changed using `--activity-style`/`-s` option: | ||
|
||
``` sh | ||
long-running-command | progressline --activity-style { dots - default | kitt | snake } | ||
# Example | ||
long-running-command | progressline --activity-style snake | ||
long-running-command | progressline -s snake | ||
``` | ||
## Installation | ||
### [Homebrew](https://brew.sh) (MacOS / Linux) | ||
Coming soon | ||
### [Mint](https://github.com/yonaskolb/Mint) (MacOS) | ||
``` sh | ||
mint install kattouf/ProgressLine | ||
``` | ||
### [Mise](Mise) (MacOS) | ||
``` sh | ||
mise use -g spm:kattouf/ProgressLine | ||
``` | ||
### Manual Installation (MacOS / Linux) | ||
Download the binary for your platform from the [releases page](https://github.com/kattouf/ProgressLine/releases), and place it in your executable path. | ||
## Contributing | ||
Feel free to open a pull request or a discussion. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
enum ANSI { | ||
// Cursor controls | ||
static func cursorUp(_ count: Int) -> String { | ||
"\u{1B}[\(count)A" | ||
} | ||
|
||
static func cursorToColumn(_ column: Int) -> String { | ||
"\u{1B}[\(column)G" | ||
} | ||
|
||
static let eraseLine = "\u{1B}[2K" | ||
|
||
// Colors and styles | ||
static let red = "\u{1B}[31m" | ||
static let green = "\u{1B}[32m" | ||
static let yellow = "\u{1B}[33m" | ||
static let blue = "\u{1B}[34m" | ||
static let magenta = "\u{1B}[35m" | ||
static let bold = "\u{1B}[1m" | ||
static let reset = "\u{1B}[0m" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ArgumentParser | ||
|
||
enum ActivityIndicatorStyle: String, CaseIterable, ExpressibleByArgument { | ||
case dots | ||
case kitt | ||
case snake | ||
} | ||
|
||
extension ActivityIndicator { | ||
static func make(style: ActivityIndicatorStyle) -> ActivityIndicator { | ||
switch style { | ||
case .dots: | ||
.dots | ||
case .kitt: | ||
.kitt | ||
case .snake: | ||
.snake | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import Foundation | ||
import TaggedTime | ||
|
||
final class ActivityIndicator: Sendable { | ||
struct Configuration { | ||
let refreshRate: Milliseconds<UInt64> | ||
let states: [String] | ||
} | ||
|
||
let configuration: Configuration | ||
|
||
init(configuration: Configuration) { | ||
self.configuration = configuration | ||
} | ||
|
||
func state(forDuration duration: Seconds<TimeInterval>) -> String { | ||
let iteration = Int(duration.milliseconds.rawValue / TimeInterval(configuration.refreshRate.rawValue)) % configuration.states.count | ||
return configuration.states[iteration] | ||
} | ||
} | ||
|
||
extension ActivityIndicator { | ||
static let dots: ActivityIndicator = { | ||
let configuration = Configuration( | ||
refreshRate: 125, | ||
states: [ | ||
"⠋", | ||
"⠙", | ||
"⠹", | ||
"⠸", | ||
"⠼", | ||
"⠴", | ||
"⠦", | ||
"⠧", | ||
"⠇", | ||
"⠏", | ||
] | ||
) | ||
return ActivityIndicator(configuration: configuration) | ||
}() | ||
|
||
static let kitt: ActivityIndicator = { | ||
let configuration = Configuration( | ||
refreshRate: 125, | ||
states: [ | ||
"▰▱▱▱▱", | ||
"▰▰▱▱▱", | ||
"▰▰▰▱▱", | ||
"▱▰▰▰▱", | ||
"▱▱▰▰▰", | ||
"▱▱▱▰▰", | ||
"▱▱▱▱▰", | ||
"▱▱▱▰▰", | ||
"▱▱▰▰▰", | ||
"▱▰▰▰▱", | ||
"▰▰▰▱▱", | ||
"▰▰▱▱▱", | ||
] | ||
) | ||
return ActivityIndicator(configuration: configuration) | ||
}() | ||
|
||
static let snake: ActivityIndicator = { | ||
let configuration = Configuration( | ||
refreshRate: 125, | ||
states: [ | ||
"▰▱▱▱▱", | ||
"▰▰▱▱▱", | ||
"▰▰▰▱▱", | ||
"▱▰▰▰▱", | ||
"▱▱▰▰▰", | ||
"▱▱▱▰▰", | ||
"▱▱▱▱▰", | ||
"▱▱▱▱▱", | ||
] | ||
) | ||
return ActivityIndicator(configuration: configuration) | ||
}() | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if os(Linux) | ||
// Linux implementation of FileHandle not Sendable | ||
@preconcurrency import Foundation | ||
#else | ||
import Foundation | ||
#endif | ||
|
||
extension FileHandle { | ||
var asyncStream: AsyncStream<Data> { | ||
AsyncStream { continuation in | ||
Task { | ||
while let data = try waitAndReadAvailableData() { | ||
continuation.yield(data) | ||
} | ||
continuation.finish() | ||
} | ||
} | ||
} | ||
|
||
private func waitAndReadAvailableData() throws -> Data? { | ||
let data = availableData | ||
guard !data.isEmpty else { | ||
return nil | ||
} | ||
return data | ||
} | ||
} |
Oops, something went wrong.