-
Notifications
You must be signed in to change notification settings - Fork 2
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 135b3ab
Showing
23 changed files
with
624 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,48 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- "v*" | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: coursier/cache-action@v6.4 | ||
- uses: VirtusLab/scala-cli-setup@v1.0 | ||
- uses: extractions/setup-just@v1 | ||
with: | ||
power: true | ||
- name: Install dependencies | ||
run: cs install scalafmt | ||
- name: Check format | ||
run: just check-format | ||
- name: Test | ||
run: just test | ||
|
||
publish: | ||
needs: test | ||
if: github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: coursier/cache-action@v6.4 | ||
- uses: VirtusLab/scala-cli-setup@v1.0 | ||
- uses: extractions/setup-just@v1 | ||
with: | ||
power: true | ||
- name: Publish | ||
run: just publish | ||
env: | ||
PUBLISH_USER: ${{ secrets.PUBLISH_USER }} | ||
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }} | ||
PUBLISH_SECRET_KEY: ${{ secrets.PUBLISH_SECRET_KEY }} | ||
PUBLISH_SECRET_KEY_PASSWORD: ${{ secrets.PUBLISH_SECRET_KEY_PASSWORD }} |
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 @@ | ||
*.class | ||
*.log | ||
*.hnir | ||
*.DS_Store | ||
*.dll | ||
|
||
# sbt specific | ||
.sbtopts | ||
.cache | ||
.history | ||
.lib/ | ||
dist/* | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
project/boot/ | ||
project/plugins/project/ | ||
|
||
# Scala-IDE specific | ||
.scala_dependencies | ||
.worksheet | ||
.bloop | ||
.bsp | ||
|
||
# Metals specific | ||
metals.sbt | ||
.metals/ | ||
|
||
# Scala-CLI | ||
.scala-build/ | ||
|
||
# Windows specific | ||
null/ |
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,5 @@ | ||
version = 3.7.16 | ||
runner.dialect = "scala3" | ||
align.preset = more | ||
docstrings.wrap = no | ||
maxColumn = 120 |
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,22 @@ | ||
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] | ||
|
||
build: format | ||
scala-cli --power compile --suppress-experimental-warning . | ||
|
||
check-format: | ||
scalafmt . --check | ||
|
||
format: | ||
scalafmt . | ||
|
||
test: | ||
scala-cli --power test --suppress-experimental-warning . | ||
|
||
run: | ||
scala-cli --power --suppress-experimental-warning . | ||
|
||
publish: | ||
scala-cli --power publish . | ||
|
||
clean: | ||
scala-cli clean . |
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,7 @@ | ||
Copyright 2023 João Costa | ||
|
||
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,15 @@ | ||
# Späti | ||
|
||
A store where you can get all your favorite Coursier packages. | ||
|
||
![A screenshot of the Späti UI](screenshot.png) | ||
|
||
## Installing | ||
|
||
Späti is not released yet, please be patient. | ||
|
||
In the meantime, you can clone this repository and run `just run`. | ||
|
||
## Acknowledgments | ||
|
||
Font: [Unscii](http://viznut.fi/unscii/) by [Viznut](http://viznut.fi/) |
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 @@ | ||
//> using scala "3.3.1" | ||
|
||
//> using lib "eu.joaocosta::minart::0.6.0-M1" | ||
//> using lib "eu.joaocosta::interim::0.1.5-1" | ||
//> using lib "io.get-coursier:coursier_2.13:2.1.7" | ||
//> using lib "io.get-coursier:coursier-install_2.13:2.1.7" | ||
|
||
//> using test.dep org.scalameta::munit::1.0.0-M10 | ||
|
||
//> using resource-dir "src/main/resources/" | ||
//> using option "-deprecation" | ||
//> using option "-feature" | ||
//> using option "-unchecked" | ||
//> using option "-language:higherKinds" | ||
//> using option "-Wunused:implicits" | ||
//> using option "-Wunused:explicits" | ||
//> using option "-Wunused:imports" | ||
//> using option "-Wunused:locals" | ||
//> using option "-Wunused:params" | ||
//> using option "-Wunused:privates" |
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,14 @@ | ||
//> using publish.name "spaeti" | ||
//> using publish.organization "eu.joaocosta" | ||
//> using publish.url "https://github.com/JD557/spaeti" | ||
//> using publish.vcs "github:JD557/spaeti" | ||
//> using publish.license "MIT" | ||
//> using publish.developer "JD557|João Costa|https://github.com/jd557" | ||
//> using publish.repository "central" | ||
//> using publish.computeVersion "git:tag" | ||
//> using publish.ci.repository "central" | ||
//> using publish.ci.user "env:PUBLISH_USER" | ||
//> using publish.ci.password "env:PUBLISH_PASSWORD" | ||
//> using publish.ci.secretKey "env:PUBLISH_SECRET_KEY" | ||
//> using publish.ci.secretKeyPassword "env:PUBLISH_SECRET_KEY_PASSWORD" | ||
//> using publish.ci.publicKey "env:PUBLISH_PUBLIC_KEY" |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
package eu.joaocosta.spaeti | ||
|
||
final case class AppId(id: Option[String], name: String) | ||
|
||
final case class AppStatus(appId: AppId, installed: Boolean) |
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,83 @@ | ||
package eu.joaocosta.spaeti | ||
|
||
import java.time.Instant | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Future, blocking} | ||
import scala.util.Try | ||
|
||
import coursier.* | ||
import coursier.install.* | ||
|
||
object CoursierApi: | ||
private val channels = Channels().withChannels( | ||
Channels.defaultChannels ++ Channels.contribChannels | ||
) | ||
|
||
private lazy val cachedAllApps = search("") | ||
|
||
/** Search all apps matching a query */ | ||
def search(query: String): Future[List[AppId]] = | ||
channels.searchAppName(List(query)).future.map { results => | ||
results | ||
.map { id => | ||
val name = Try( | ||
channels.appDescriptor(id).unsafeRun().appDescriptor.nameOpt | ||
).toOption.flatten | ||
AppId(Some(id), name.getOrElse(id)) | ||
} | ||
} | ||
|
||
/** List all installed apps */ | ||
def list(): List[AppId] = | ||
InstallDir().list().toList.map { name => | ||
val source = List(name, name + ".bat").flatMap { file => | ||
Try( | ||
InfoFile.readSource(InstallDir().baseDir.resolve(file)).map(_._1) | ||
).toOption.flatten | ||
}.headOption | ||
AppId(source.map(_.id), name) | ||
} | ||
|
||
/** Fetches the status of all known apps | ||
* | ||
* This method caches the result of the first request to avoid calls to the server. | ||
*/ | ||
def fetchStatus(): Future[List[AppStatus]] = cachedAllApps.map { allApps => | ||
val installedApps = list().toSet | ||
(allApps.toSet ++ installedApps) | ||
.map(appId => AppStatus(appId, installedApps(appId))) | ||
.toList | ||
.sortBy(app => (!app.installed, app.appId.name, app.appId.id)) | ||
} | ||
|
||
/** Installs an app */ | ||
def install(appId: AppId): Future[Option[Boolean]] = | ||
appId.id | ||
.map(id => | ||
channels | ||
.appDescriptor(id) | ||
.map(appInfo => InstallDir().createOrUpdate(appInfo)) | ||
.future | ||
) | ||
.getOrElse( | ||
Future.failed(new Exception("Cannot install app with unknown id.")) | ||
) | ||
|
||
/** Uninstalls an app */ | ||
def uninstall(appId: AppId): Future[Unit] = | ||
Future(blocking(InstallDir().delete(appId.name))) | ||
|
||
/** Updates an app */ | ||
def update(appId: AppId): Future[Option[Boolean]] = | ||
appId.id | ||
.map(id => | ||
channels | ||
.appDescriptor(id) | ||
.map(appInfo => InstallDir().createOrUpdate(appInfo, Instant.now(), force = true)) | ||
.future | ||
) | ||
.getOrElse( | ||
Future.failed(new Exception("Cannot update app with unknown id.")) | ||
) |
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,25 @@ | ||
package eu.joaocosta.spaeti | ||
|
||
import eu.joaocosta.interim.* | ||
import eu.joaocosta.interim.InterIm.* | ||
import eu.joaocosta.minart.graphics.Canvas.Settings | ||
import eu.joaocosta.spaeti.components.* | ||
|
||
object MainApp: | ||
val uiContext = new UiContext() | ||
val fullArea = Rect(0, 0, 600, 800) | ||
val headerSize = 32 | ||
|
||
val appState = Ref(MainState()) | ||
|
||
def application(inputState: InputState) = | ||
ui(inputState, uiContext): | ||
onTop(errorWindow(Rect(0, 0, 400, 200).centerAt(fullArea.centerX, fullArea.centerY))(appState)) | ||
dynamicRows(fullArea, padding = 0): nextRow => | ||
header(nextRow(headerSize))(appState) | ||
if (appState.get.isLoading || appState.get.isPerformingOperation) | ||
loading(nextRow(maxSize), appState.get.isPerformingOperation) | ||
else appList(nextRow(maxSize))(appState) | ||
|
||
@main def main() = | ||
MinartBackend.run(Settings(width = fullArea.w, height = fullArea.h, title = "Späti"))(application) |
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,46 @@ | ||
package eu.joaocosta.spaeti | ||
|
||
import scala.concurrent.{Await, Future} | ||
import scala.concurrent.duration._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
/** Main application state | ||
* | ||
* @param allApps list of all known apps and their status | ||
* @param runningOperation future with the state of any currently running operation | ||
* @param query search query | ||
* @param offset scroll offset | ||
*/ | ||
final case class MainState( | ||
allApps: Future[List[AppStatus]] = CoursierApi.fetchStatus(), | ||
runningOperation: Option[Future[_]] = None, | ||
query: String = "", | ||
offset: Int = 0 | ||
): | ||
/** If true, the list of known apps are being loaded */ | ||
def isLoading: Boolean = !allApps.isCompleted | ||
|
||
/** If true, an operation is currently being performed */ | ||
def isPerformingOperation: Boolean = runningOperation.exists(!_.isCompleted) | ||
|
||
/** List of apps filtered by the query string */ | ||
lazy val apps: List[AppStatus] = Await | ||
.result(allApps, 30.seconds) | ||
.filter(app => app.appId.name.contains(query) || app.appId.id.getOrElse("").contains(query)) | ||
|
||
/** Creates a new MainState with a running operation | ||
* | ||
* Once the operation is completed, it also update the app status | ||
*/ | ||
def runOperation(op: Future[_]): MainState = | ||
copy( | ||
allApps = op.transformWith(_ => CoursierApi.fetchStatus()), | ||
runningOperation = Some(op) | ||
) | ||
|
||
/** Error message, populated if the running operation failed */ | ||
def errorMessage: Option[String] = | ||
runningOperation | ||
.flatMap(_.value) | ||
.flatMap(_.failed.toOption) | ||
.map(_.getMessage) |
Oops, something went wrong.