🎉 Begin project.

This commit is contained in:
Александр Колосов 2024-01-30 02:01:31 +05:00
parent 440fd4d5d4
commit 5bb0e89548
32 changed files with 45 additions and 1447 deletions

View File

@ -1,166 +1,22 @@
root = true
[*] [*]
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
indent_size=4
indent_style=space
insert_final_newline=false
max_line_length=120
tab_width=4
trim_trailing_whitespace=false
ij_continuation_indent_size=8
ij_formatter_off_tag=@formatter:off
ij_formatter_on_tag=@formatter:on
ij_formatter_tags_enabled=false
ij_smart_tabs=false
ij_visual_guides=none
ij_wrap_on_typing=true
[*.properties]
ij_properties_align_group_field_declarations=false
ij_properties_keep_blank_lines=false
ij_properties_key_value_delimiter=equals
ij_properties_spaces_around_key_value_delimiter=false
[*.proto]
indent_size=2
tab_width=2
ij_continuation_indent_size=4
ij_protobuf_keep_blank_lines_in_code=2
ij_protobuf_keep_indents_on_empty_lines=false
ij_protobuf_keep_line_breaks=true
ij_protobuf_space_after_comma=true
ij_protobuf_space_before_comma=false
ij_protobuf_spaces_around_assignment_operators=true
ij_protobuf_spaces_within_braces=false
ij_protobuf_spaces_within_brackets=false
[.editorconfig]
ij_editorconfig_align_group_field_declarations=false
ij_editorconfig_space_after_colon=false
ij_editorconfig_space_after_comma=false
ij_editorconfig_space_before_colon=false
ij_editorconfig_space_before_comma=false
ij_editorconfig_spaces_around_assignment_operators=false
[{*.ant,*.appxmanifest,*.axml,*.cscfg,*.csdef,*.disco,*.filelayout,*.fxml,*.jhm,*.jnlp,*.jrxml,*.manifest,*.myapp,*.nuspec,*.rng,*.stylecop,*.svcmap,*.tld,*.wadcfgx,*.webref,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul,StyleCop.Cache}]
ij_xml_align_attributes=true
ij_xml_align_text=false
ij_xml_attribute_wrap=normal
ij_xml_block_comment_add_space=false
ij_xml_block_comment_at_first_column=true
ij_xml_keep_blank_lines=2
ij_xml_keep_indents_on_empty_lines=false
ij_xml_keep_line_breaks=true
ij_xml_keep_line_breaks_in_text=true
ij_xml_keep_whitespaces=false
ij_xml_keep_whitespaces_around_cdata=preserve
ij_xml_keep_whitespaces_inside_cdata=false
ij_xml_line_comment_at_first_column=true
ij_xml_space_after_tag_name=false
ij_xml_space_around_equals_in_attribute=false
ij_xml_space_inside_empty_tag=false
ij_xml_text_wrap=normal
max_line_length=off
trim_trailing_whitespace=true
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true
[{*.go,Makefile,.gitmodules,go.mod,go.sum}]
indent_style = tab
[*.md]
indent_style = tab
trim_trailing_whitespace = false
[*.{yml,yaml,json}]
indent_style = space
indent_size = 2 indent_size = 2
[{*.bash,*.sh,*.zsh}] [*.{js,jsx,ts,tsx,css,less,sass,scss,vue,py}]
indent_size=2 indent_style = space
tab_width=2 indent_size = 4
ij_shell_binary_ops_start_line=false
ij_shell_keep_column_alignment_padding=false
ij_shell_minify_program=false
ij_shell_redirect_followed_by_space=false
ij_shell_switch_cases_indented=false
ij_shell_use_unix_line_separator=true
[{*.har,*.json}]
indent_size=2
tab_width=2
ij_json_keep_blank_lines_in_code=0
ij_json_keep_indents_on_empty_lines=false
ij_json_keep_line_breaks=true
ij_json_space_after_colon=true
ij_json_space_after_comma=true
ij_json_space_before_colon=true
ij_json_space_before_comma=false
ij_json_spaces_within_braces=false
ij_json_spaces_within_brackets=false
ij_json_wrap_long_lines=false
[{*.htm,*.html,*.sht,*.shtm,*.shtml}]
ij_html_add_new_line_before_tags=body,div,p,form,h1,h2,h3
ij_html_align_attributes=true
ij_html_align_text=false
ij_html_attribute_wrap=normal
ij_html_block_comment_add_space=false
ij_html_block_comment_at_first_column=true
ij_html_do_not_align_children_of_min_lines=0
ij_html_do_not_break_if_inline_tags=title,h1,h2,h3,h4,h5,h6,p
ij_html_do_not_indent_children_of_tags=html,body,thead,tbody,tfoot
ij_html_enforce_quotes=false
ij_html_inline_tags=a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var
ij_html_keep_blank_lines=2
ij_html_keep_indents_on_empty_lines=false
ij_html_keep_line_breaks=true
ij_html_keep_line_breaks_in_text=true
ij_html_keep_whitespaces=false
ij_html_keep_whitespaces_inside=span,pre,textarea
ij_html_line_comment_at_first_column=true
ij_html_new_line_after_last_attribute=never
ij_html_new_line_before_first_attribute=never
ij_html_quote_style=double
ij_html_remove_new_line_before_tags=br
ij_html_space_after_tag_name=false
ij_html_space_around_equality_in_attribute=false
ij_html_space_inside_empty_tag=false
ij_html_text_wrap=normal
[{*.markdown,*.md}]
indent_size=2
tab_width=2
ij_continuation_indent_size=4
ij_visual_guides=120
ij_markdown_force_one_space_after_blockquote_symbol=true
ij_markdown_force_one_space_after_header_symbol=true
ij_markdown_force_one_space_after_list_bullet=true
ij_markdown_force_one_space_between_words=true
ij_markdown_insert_quote_arrows_on_wrap=true
ij_markdown_keep_indents_on_empty_lines=false
ij_markdown_keep_line_breaks_inside_text_blocks=true
ij_markdown_max_lines_around_block_elements=1
ij_markdown_max_lines_around_header=1
ij_markdown_max_lines_between_paragraphs=1
ij_markdown_min_lines_around_block_elements=1
ij_markdown_min_lines_around_header=1
ij_markdown_min_lines_between_paragraphs=1
ij_markdown_wrap_text_if_long=true
ij_markdown_wrap_text_inside_blockquotes=true
[{*.pb,*.textproto}]
indent_size=2
tab_width=2
ij_continuation_indent_size=4
ij_prototext_keep_blank_lines_in_code=2
ij_prototext_keep_indents_on_empty_lines=false
ij_prototext_keep_line_breaks=true
ij_prototext_space_after_colon=true
ij_prototext_space_after_comma=true
ij_prototext_space_before_colon=false
ij_prototext_space_before_comma=false
ij_prototext_spaces_within_braces=true
ij_prototext_spaces_within_brackets=false
[{*.yaml,*.yml}]
indent_size=2
ij_yaml_align_values_properties=do_not_align
ij_yaml_autoinsert_sequence_marker=true
ij_yaml_block_mapping_on_new_line=false
ij_yaml_indent_sequence_value=true
ij_yaml_keep_indents_on_empty_lines=false
ij_yaml_keep_line_breaks=true
ij_yaml_sequence_on_new_line=false
ij_yaml_space_before_colon=false
ij_yaml_spaces_within_braces=true
ij_yaml_spaces_within_brackets=true

356
.gitignore vendored
View File

@ -1,345 +1,23 @@
## Ignore Visual Studio temporary files, build results, and # Mac OS X files
## files generated by popular Visual Studio add-ons. .DS_Store
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
*.yaml
# User-specific files # Binaries for programs and plugins
*.rsuser *.exe
*.suo *.exe~
*.user *.dll
*.userosscache *.so
*.sln.docstates *.dylib
# User-specific files (MonoDevelop/Xamarin Studio) # Test binary, build with `go test -c`
*.userprefs *.test
# Build results # Output of the go coverage tool, specifically when used with LiteIDE
[Dd]ebug/ *.out
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.vs/ .glide/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files # Dependency directories (remove the comment below to include it)
Generated\ Files/ # vendor/
# MSTest test Results .idea
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- Backup*.rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
*.DotSettings
*.DS_Store
**/*.Production.json
Logs/

View File

@ -8,10 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 🆕 Added ### 🆕 Added
- Add dashboard for dependencies
- Add header with toggle
- Add hotkey for exit (q)
### 🛠 Changed ### 🛠 Changed
_Список изменившейся функциональности._ _Список изменившейся функциональности._

1
Makefile Normal file
View File

@ -0,0 +1 @@
# note: call scripts from /scripts

20
TLD.sln
View File

@ -1,20 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TUI", "src\TUI\TUI.csproj", "{F92C03F7-2A65-4D0A-9736-13E749AF6903}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BF07B744-015F-4904-B1B6-CBDE266A07B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF07B744-015F-4904-B1B6-CBDE266A07B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF07B744-015F-4904-B1B6-CBDE266A07B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF07B744-015F-4904-B1B6-CBDE266A07B0}.Release|Any CPU.Build.0 = Release|Any CPU
{F92C03F7-2A65-4D0A-9736-13E749AF6903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F92C03F7-2A65-4D0A-9736-13E749AF6903}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F92C03F7-2A65-4D0A-9736-13E749AF6903}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F92C03F7-2A65-4D0A-9736-13E749AF6903}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0
changelogs/.gitkeep Normal file
View File

7
cmd/tld/tld.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello, world.")
}

0
configs/.gitkeep Normal file
View File

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module dnw/tld
go 1.21.6

0
internal/.gitkeep Normal file
View File

0
scripts/.gitkeep Normal file
View File

View File

@ -1,16 +0,0 @@
using TUI.UserInterface;
namespace TUI.Controls;
public class Copyright : IControl<string>
{
public void Render(string author, Position position)
{
const string icon = "© ";
Console.SetCursorPosition(position.Left - icon.Width(), position.Top);
var copyright = $"{icon}{author}".Hint();
Console.Write(copyright);
}
}

View File

@ -1,60 +0,0 @@
using System.Text;
using TUI.UserInterface;
namespace TUI.Controls;
public class Dashboard : IControl<string>
{
public void Render(string title, Position position)
{
Console.SetCursorPosition(position.Left, position.Top);
RenderTopLine(title);
var marginTop = Theme.BorderWidth + Theme.Padding + position.Top;
var dashboardHeight = Console.WindowHeight - Theme.BorderWidth;
for (var top = marginTop; top < dashboardHeight; top++)
{
RenderMiddleLine();
}
RenderBottomLine();
}
private static void RenderMiddleLine()
{
Console.Write("│".Primary());
Console.Write(new string(' ', Console.WindowWidth - Theme.BorderWidth * 2));
Console.WriteLine("│".Primary());
}
private static void RenderBottomLine()
{
var lineWidth = Console.WindowWidth - Theme.BorderWidth * 2;
Console.Write("└".Primary());
Console.Write('─'.Repeat(lineWidth).Primary());
Console.WriteLine("┘".Primary());
}
private static void RenderTopLine(string title)
{
var lineWidth =
(Console.WindowWidth - title.Width() - Theme.BorderWidth * 2 - Theme.Padding * 2) /
2;
var topLine = new StringBuilder();
topLine.Append("┌");
topLine.Append('─'.Repeat(lineWidth));
topLine.AppendFormat("{0}{1}{0}", ' '.Repeat(Theme.Padding), title);
if (title.Width() % 2 == 1)
{
topLine.Append('─');
}
topLine.Append('─'.Repeat(lineWidth));
topLine.Append("┐");
Console.WriteLine(topLine.ToString().Primary());
}
}

View File

@ -1,73 +0,0 @@
using TUI.Dashboards;
using TUI.Domain;
using TUI.UserInterface;
namespace TUI.Controls;
public class Display
{
private bool _headerInDisplay = true;
public readonly Header Header;
public readonly Copyright Copyright;
public readonly DependencyDashboard DependencyDashboard;
private Project _currentProject;
public Display()
{
Header = new Header();
Copyright = new Copyright();
DependencyDashboard = new DependencyDashboard();
Render();
}
public void OpenDeps(Project project)
{
_currentProject = project;
var dashboardPosition = new Position(0, Header.Height);
DependencyDashboard.Render(_currentProject, dashboardPosition);
}
private void ResizeDependencies(bool full)
{
var dashboardPosition = new Position(0, full ? 0 : Header.Height);
DependencyDashboard.Render(_currentProject, dashboardPosition);
}
public void Render()
{
var headerPosition = new Position(0, 0);
Header.Render(headerPosition);
const string copyrightText = "Kolosov Aleksandr";
var copyrightPosition = new Position(
Console.WindowWidth - copyrightText.Width(),
Console.WindowHeight);
Copyright.Render(copyrightText, copyrightPosition);
}
public void ToggleHeader()
{
_headerInDisplay = !_headerInDisplay;
if (_headerInDisplay)
{
var headerPosition = new Position(0, 0);
Header.Render(headerPosition);
}
ResizeDependencies(!_headerInDisplay);
}
public void Next()
{
DependencyDashboard.Next();
}
public void Previous()
{
DependencyDashboard.Previous();
}
}

View File

@ -1,11 +0,0 @@
namespace TUI.Controls;
public interface IControl
{
void Render(Position position);
}
public interface IControl<in TProps>
{
void Render(TProps props, Position position);
}

View File

@ -1,3 +0,0 @@
namespace TUI.Controls;
public record Position(int Left, int Top);

View File

@ -1,74 +0,0 @@
using Pastel;
using TUI.UserInterface;
namespace TUI.Controls;
public record TableProps(IEnumerable<string> HeaderCells,
IEnumerable<string> Rows,
int TitleWidth,
int ColumnWidth);
public class Table : IControl<TableProps>
{
private Position _position;
private int _selectedRowId;
public void Render(TableProps props, Position position)
{
_position = position;
Console.SetCursorPosition(_position.Left, _position.Top);
Console.Write(' '.Repeat(props.TitleWidth));
foreach (var headerCell in props.HeaderCells)
{
Console.Write(' '.Repeat(props.ColumnWidth - headerCell.Width()) + headerCell);
}
}
private readonly Dictionary<int, string> _rows = new();
public void RenderRow(int rowId, string rowText, string? bgColor = default)
{
var padRight = ' '.Repeat(Console.WindowWidth - rowText.Width() - Theme.BorderWidth * 2);
_rows[rowId] = rowText + padRight;
Console.SetCursorPosition(_position.Left, _position.Top + rowId);
Console.Write(string.IsNullOrEmpty(bgColor) ? rowText : rowText.PastelBg(bgColor));
}
public void Next()
{
if (_selectedRowId >= _rows.Count)
{
return;
}
RemoveHoverFromCurrentRow();
RenderRow(++_selectedRowId, _rows[_selectedRowId], Palette.HoverColor);
}
private void RemoveHoverFromCurrentRow()
{
if (_rows.TryGetValue(_selectedRowId, out var row))
{
RenderRow(_selectedRowId, row);
}
}
public void Previous()
{
if (_selectedRowId == 0)
{
Next();
}
if (_selectedRowId == 1)
{
return;
}
RemoveHoverFromCurrentRow();
RenderRow(--_selectedRowId, _rows[_selectedRowId], Palette.HoverColor);
}
}

View File

@ -1,215 +0,0 @@
using System.Diagnostics;
using System.Net;
using System.Text.Json;
using Pastel;
using TUI.Controls;
using TUI.Domain;
using TUI.Settings;
using TUI.UserInterface;
namespace TUI.Dashboards;
public class DependencyDashboard : IControl<Project>
{
private const int TitleWidth = 25;
private const int ColumnWidth = 10;
private readonly Table _table = new();
public void Render(Project project, Position position)
{
var dashboard = new Dashboard();
dashboard.Render(project.Icon, position);
var header = project.Dependencies.Select(GetConventionVersion).ToArray();
var rows = project.Sources.Select(GetTitle).ToArray();
var tablePosition = new Position(
position.Left + Theme.BorderWidth,
position.Top + Theme.BorderWidth);
var tableProps = new TableProps(header, rows, TitleWidth, ColumnWidth);
_table.Render(tableProps, tablePosition);
for (var rowId = 0; rowId < rows.Length; rowId++)
{
var actualDependencies = GetDependencies(project.Sources[rowId], project.Dependencies);
_table.RenderRow(rowId + 1, rows[rowId] + actualDependencies);
}
}
private static string GetDependencies(SourceDto sourceDto, IEnumerable<DependencyDto> conventionDependencies)
{
try
{
var package = DownloadPackage(sourceDto);
return string.Join("",
conventionDependencies
.Select(dependency => GetVersion(dependency, package))
.Select(RenderCurrentVersion));
}
catch (HttpRequestException exception)
{
switch (exception.StatusCode)
{
case HttpStatusCode.BadRequest:
return " Request have errors.".Pastel(Palette.ErrorColor);
case HttpStatusCode.Forbidden:
return " Not enough rights.".Pastel(Palette.ErrorColor);
case HttpStatusCode.NotFound:
return " Repository or branch master not found.".Pastel(Palette.ErrorColor);
}
throw;
}
catch (Exception exception)
{
Debugger.Break();
return "󰋔 We tried to send a request but couldn't. Check your configuration.".Pastel(Palette.ErrorColor);
}
}
private static string GetVersion(DependencyDto dependency, Package package)
{
var currentVersion = package.ParseVersion(dependency.Name);
if (currentVersion == null)
{
return Icons.NotFound;
}
var conventionVersion = dependency.Version?.ToVersion();
return PaintingVersion(currentVersion, conventionVersion);
}
private static string PaintingVersion(Version current, Version? convention)
{
var textVersion = current.ToString();
if (current > convention)
{
return textVersion.Info();
}
if (current < convention)
{
return current.Major == convention.Major ? textVersion.Primary() : textVersion.Warning();
}
return textVersion.Hint();
}
private readonly static Dictionary<string, Package> Packages = new();
private static Package DownloadPackage(SourceDto sourceDto)
{
if (Packages.TryGetValue(sourceDto.Repo, out var downloadPackage))
{
return downloadPackage;
}
using HttpClient client = new();
var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo;
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
var package = JsonSerializer.Deserialize<Package>(json);
Packages.Add(endpoint, package);
return package;
}
private static string GetGitlabEndpoint(SourceDto sourceDto)
{
var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
return $"{sourceDto.Repo}/api/v4/projects/{sourceDto.ProjectId}/repository/files/package.json/raw?" +
$"private_token={token}&ref=master";
}
private static string GetConventionVersion(DependencyDto dependencyDto)
{
return dependencyDto.Icon.Pastel(dependencyDto.Color) + dependencyDto.Version.Primary();
}
private static string RenderCurrentVersion(string version)
{
var versionWidth = version.Width();
if (versionWidth == 0)
{
return ' '.Repeat(ColumnWidth - 1) + Icons.NotFound.Hint();
}
return ' '.Repeat(ColumnWidth - versionWidth) + version;
}
private static string GetTitle(SourceDto sourceDto)
{
var title = "";
title += RenderPadding();
title += RenderTags(sourceDto);
if (title.Width() + sourceDto.Name.Length + Theme.Padding <= TitleWidth)
{
title += sourceDto.Name;
}
else
{
var maxNameWidth = TitleWidth - title.Width() - Theme.Padding;
title += $"{sourceDto.Name[..(maxNameWidth - 1)]}{"#".Hint()}";
}
title += RenderPadding();
return $"{title}{' '.Repeat(TitleWidth - title.Width())}";
}
private static string RenderPadding()
{
return new string(' ', Theme.Padding);
}
private static string RenderTags(SourceDto sourceDto)
{
var tags = "";
tags += GetGitApplication(sourceDto);
tags += " ";
tags += sourceDto.Tags.Have("public") ? Icons.NetworkPublic : Icons.NetworkPrivate;
tags += " ";
tags += sourceDto.Tags.Have("seo") ? Icons.SEO : Icons.SEO.Disable();
tags += " ";
tags += sourceDto.Tags.Have("auth") ? Icons.Auth : Icons.Auth.Disable();
tags += " ";
tags += GetApplicationType(sourceDto);
tags += " ";
return tags;
}
private static string GetApplicationType(SourceDto sourceDto)
{
foreach (var application in Icons.Applications)
{
if (sourceDto.Tags.Have(application.Value))
return application.Key;
}
return Icons.Undefined;
}
private static string GetGitApplication(SourceDto sourceDto) => sourceDto.Repo switch
{
{ } url when url.Contains("gitlab") => Icons.GitLab,
{ } url when url.Contains("github") => Icons.GitHub,
_ => Icons.Git
};
public void Next()
{
_table.Next();
}
public void Previous()
{
_table.Previous();
}
}

View File

@ -1,42 +0,0 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace TUI.Domain;
public class Package
{
[JsonPropertyName("dependencies")]
public JsonObject? Dependencies { get; set; }
[JsonPropertyName("devDependencies")]
public JsonObject? DevDependencies { get; set; }
[JsonPropertyName("engines")]
public JsonObject? Engines { get; set; }
public Version? ParseVersion(string? dependencyName)
{
if (dependencyName == null)
{
return null;
}
JsonNode? version = null;
var lowerDependencyName = dependencyName.ToLower();
Dependencies?.TryGetPropertyValue(lowerDependencyName, out version);
if (version == null)
{
Engines?.TryGetPropertyValue(lowerDependencyName, out version);
}
if (version == null)
{
DevDependencies?.TryGetPropertyValue(lowerDependencyName, out version);
}
return version?.GetValue<string>().ToVersion();
}
}

View File

@ -1,21 +0,0 @@
using TUI.Settings;
using YamlDotNet.Serialization;
namespace TUI.Domain;
[YamlSerializable]
public class Project
{
[YamlMember]
public string Icon { get; set; }
[YamlMember]
public string Name { get; set; }
[YamlMember]
public DependencyDto[] Dependencies { get; set; }
[YamlMember]
public IList<SourceDto> Sources { get; set; }
}

View File

@ -1,22 +0,0 @@
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace TUI.Domain;
[YamlSerializable]
public class Settings
{
public static Settings Init()
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
using var sr = new StreamReader("settings.yaml");
return deserializer.Deserialize<Settings>(sr.ReadToEnd());
}
[YamlMember]
public Project[] Projects { get; set; }
}

View File

@ -1,45 +0,0 @@
using System.Text.RegularExpressions;
namespace TUI;
public static class Extensions
{
public static bool Have(this IEnumerable<string> array, string findValue)
{
return array.Any(item => item == findValue);
}
public static string Repeat(this char symbol, int repeatCount)
{
return repeatCount < 0 ? "" : new string(symbol, repeatCount);
}
public static string RemoveColors(this string text)
{
return Regex.Replace(text, @"\S\[(\d{0,3}[;m][_]?){0,5}", "");
}
public static int Width(this string text)
{
if (string.IsNullOrEmpty(text))
{
return 0;
}
var clearText = text.RemoveColors();
var stringInfo = new System.Globalization.StringInfo(clearText);
return stringInfo.LengthInTextElements;
}
public static Version? ToVersion(this string textVersion)
{
var version = textVersion.Replace("^", "").Replace("~", "").Split(".");
if (version.Length != 3)
return null;
var major = Convert.ToInt32(version[0]);
var minor = Convert.ToInt32(version[1]);
var patch = Convert.ToInt32(version[2].Split('-')[0]);
return new Version(major, minor, patch);
}
}

View File

@ -1,32 +0,0 @@
using TUI.Controls;
using Settings = TUI.Domain.Settings;
Console.Clear();
Console.CursorVisible = false;
var settings = Settings.Init();
var display = new Display();
display.OpenDeps(settings.Projects[0]);
var hotKey = ConsoleKey.NoName;
do
{
switch (hotKey)
{
case ConsoleKey.DownArrow:
display.Next();
break;
case ConsoleKey.UpArrow:
display.Previous();
break;
case ConsoleKey.E:
display.ToggleHeader();
break;
}
hotKey = Console.ReadKey(intercept: true).Key;
} while (hotKey != ConsoleKey.Q);
Console.Clear();

View File

@ -1,32 +0,0 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Settings;
[DataContract]
[YamlSerializable]
public class DependencyDto
{
private string _icon;
[DataMember]
[YamlMember]
public string? Name { get; set; }
[DataMember]
[YamlMember]
public string? Icon
{
get => $" {_icon} ";
set => _icon = value;
}
[DataMember]
[YamlMember]
public string? Version { get; set; }
[DataMember]
[YamlMember]
public string? Color { get; set; }
}

View File

@ -1,20 +0,0 @@
using YamlDotNet.Serialization;
namespace TUI.Settings;
[YamlSerializable]
public class SourceDto
{
[YamlMember]
public string[] Tags { get; set; }
[YamlMember]
public string Name { get; set; }
[YamlMember]
public int ProjectId { get; set; } = 0;
[YamlMember]
public string Repo { get; set; }
}

View File

@ -1,22 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>0.1.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pastel" Version="4.1.0" />
<PackageReference Include="YamlDotNet" Version="13.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="settings.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,82 +0,0 @@
using TUI.Controls;
namespace TUI.UserInterface;
public class Header : IControl
{
public const int LogoWidth = 16;
public const int Height = 6;
public const int MaxHeaderBlocksWidth = 16;
private readonly Dictionary<string, string> _hotKeys = new()
{
{ "", "select prev" },
{ "", "select next" },
{ "󰬌", "toggle head" },
{ "󰬘", "quit" },
};
private readonly Dictionary<string, string> _hints = new()
{
{ "󰎔", "too new".Info() },
{ "", "so good" },
{ "", "be nice".Primary() },
{ "󰬟", "too old".Warning() }
};
private readonly Dictionary<string, string> _tags = new()
{
{ Icons.Auth, "Auth" },
{ Icons.NetworkPublic, "WWW" },
{ Icons.SEO, "SEO" },
{ Icons.GitLab, "VCS" },
};
public void Render(Position position)
{
Console.SetCursorPosition(position.Left, position.Top);
for (var i = 1; i <= Height; i++)
{
Console.WriteLine(new string(' ', Console.WindowWidth - LogoWidth));
}
RenderBlock(0, _hints);
RenderBlock(1, _tags);
RenderBlock(2, Icons.Applications);
RenderBlock(3, _hotKeys);
RenderLogo();
}
private static void RenderBlock(int blockNumber, Dictionary<string, string> items)
{
var leftPadding = Theme.Padding + blockNumber * MaxHeaderBlocksWidth;
var hotKeyNumber = 0;
foreach (var item in items)
{
Console.SetCursorPosition(leftPadding, Theme.Padding + hotKeyNumber++);
Console.Write((item.Key + " " + item.Value).Hint());
}
}
private static void RenderLogo()
{
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 0);
Console.WriteLine(" ╭━━━━┳╮".Primary() + "".Hint() + "╭━━━╮ ".Primary());
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 1);
Console.WriteLine(" ┃╭╮╭╮┃┃".Primary() + "".Hint() + "╰╮╭╮┃ ".Primary());
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 2);
Console.WriteLine(" ╰╯┃┃╰┫┃".Primary() + "".Hint() + "┃┃┃┃ ".Primary());
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 3);
Console.WriteLine(" ".Hint() + "┃┃".Primary() + "".Hint() + "┃┃".Primary() + "".Hint() +
"╭╮┃┃┃┃ ".Primary());
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 4);
Console.WriteLine(" ".Hint() + "┃┃".Primary() + "".Hint() + "┃╰━╯┣╯╰╯┃ ".Primary());
Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 5);
Console.WriteLine("".Hint() + "╰╯".Primary() + "".Hint() + "╰━━━┻━━━╯ ".Primary());
}
}

View File

@ -1,32 +0,0 @@
using Pastel;
namespace TUI.UserInterface;
public static class Icons
{
public static string GitLab => GetIcon("", "E24329");
public static string GitHub => GetIcon("", "ADBAC7");
public static string Git => GetIcon("", "F14E32");
public static string NetworkPublic => GetIcon("󰞉", "00FFFF");
public static string NetworkPrivate => GetIcon("󰕑");
public static string Undefined => GetIcon("");
public static string Site => GetIcon("", "BF40BF");
public static string Api => GetIcon("", "7F52FF");
public static string DockerImage => GetIcon("󰡨", "086DD7");
public static string NpmPackage => GetIcon("", "CB0000");
public static string SEO => GetIcon("󰚩", "4285F4");
public static string Auth => GetIcon("", "FFD700");
public static string NotFound => GetIcon("");
public readonly static Dictionary<string, string> Applications = new()
{
{ NpmPackage, "package" },
{ DockerImage, "image" },
{ Site, "site" },
{ Api, "api" },
};
private static string GetIcon(string icon, string? activeColor = null) =>
icon.Pastel(activeColor ?? Palette.HintColor);
}

View File

@ -1,21 +0,0 @@
using Pastel;
namespace TUI.UserInterface;
public static class Palette
{
public const string HoverColor = "292928";
public const string PrimaryColor = "84BA64";
public const string HintColor = "71797E";
public const string ErrorColor = "CA3433";
public const string WarningColor = "EC9706";
public const string InfoColor = "25799F";
public static string Primary(this string currentText) => currentText.Pastel(PrimaryColor);
public static string Hint(this string currentText) => currentText.Pastel(HintColor);
public static string Disable(this string currentText) => currentText.RemoveColors().Pastel(HintColor);
public static string Warning(this string currentText) => currentText.Pastel(WarningColor);
public static string Error(this string currentText) => currentText.Pastel(ErrorColor);
public static string Info(this string currentText) => currentText.Pastel(InfoColor);
}

View File

@ -1,93 +0,0 @@
using TUI.Settings;
namespace TUI.UserInterface;
public static class Panel
{
private const int BorderWidth = 1;
private const int ColumnWidth = 10;
private const int TitleWidth = 35;
private const int TagCount = 5;
private const int TagWidth = 2;
public static void RenderRows(SourceDto[] sources, int selectedRowNumber)
{
for (var index = 0; index < sources.Length; index++)
{
Console.SetCursorPosition(Theme.Padding,
6 + index + _marginTop + BorderWidth +
Theme.Padding);
if (selectedRowNumber == index + 1)
{
// resultText = resultText.PastelBg("292928");
}
// Console.Write(resultText);
}
for (var index = 0; index < sources.Length; index++)
{
Console.SetCursorPosition(TitleWidth,
6 + index + _marginTop + BorderWidth + Theme.Padding);
// var source = sources[index];
// var package = DownloadPackage(source);
// var resultText = package.Dependencies.React;
// resultText = new string(' ', ColumnWidth - resultText.Width()) + resultText;
// if (selectedRowNumber == index + 1)
// {
// resultText = resultText.PastelBg("292928");
// }
//
// Console.Write(resultText);
}
// for (var index = 0; index < sources.Length; index++)
// {
// var loading = true;
// var braille = new[] { "⠿", "⠧", "⠏", "⠛", "⠹", "⠼", "⠶" };
// var braileNumber = 0;
// do
// {
// var resultText = braille[braileNumber];
// if (selectedRowNumber == index + 1)
// {
// resultText = resultText.PastelBg("292928");
// }
//
// Console.SetCursorPosition(ColumnWidth + TagCountInLeftPanel * 2, index + 2);
// Console.Write(resultText);
// Thread.Sleep(100);
// if (braileNumber == braille.Length - 1)
// {
// braileNumber = 0;
// loading = false;
// }
// else
// {
// braileNumber++;
// }
// } while (loading);
//
// Console.SetCursorPosition(ColumnWidth + TagCountInLeftPanel * 2, index + 2);
// Console.Write(braille[0]);
// }
}
private static int _marginTop;
// private static Package DownloadPackage(Source source)
// {
// if (Packages.TryGetValue(source.Repo, out var downloadPackage))
// {
// return downloadPackage;
// }
//
// using HttpClient client = new();
// var json = client.GetStringAsync(source.Repo).GetAwaiter().GetResult();
// var package = JsonSerializer.Deserialize<Package>(json);
// Packages.Add(source.Repo, package);
// return package;
// }
}

View File

@ -1,7 +0,0 @@
namespace TUI.UserInterface;
public static class Theme
{
public static int Padding = 1;
public static int BorderWidth = 1;
}

0
test/test.go Normal file
View File