Skip to content

Commit

Permalink
terminal experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Nov 22, 2023
1 parent 7f69f52 commit ad5c3cd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
24 changes: 12 additions & 12 deletions src/Stowage.Terminal/AppTopLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ class AppTopLevel : Toplevel {

public AppTopLevel(IFileStorage fs) {
_fs = fs;
ColorScheme = Colors.Base;

MenuBar = new MenuBar(new MenuBarItem[] {
new MenuBarItem("_File", new MenuItem[] {
new MenuItem("_Quit", "", () => Application.RequestStop()),
}),
new MenuBarItem("_Help", new MenuItem[] {
new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")),
}),
});
MenuBar.Visible = true;
//ColorScheme = Colors.Base;

//MenuBar = new MenuBar(new MenuBarItem[] {
// new MenuBarItem("_File", new MenuItem[] {
// new MenuItem("_Quit", "", () => Application.RequestStop()),
// }),
// new MenuBarItem("_Help", new MenuItem[] {
// new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")),
// }),
//});
//MenuBar.Visible = true;

_fsView1 = new FSView(_fs) {
X = 0,
Y = 1,
Y = 0,
Width = Dim.Percent(50),
Height = Dim.Fill() - 1
};
Expand Down
45 changes: 25 additions & 20 deletions src/Stowage.Terminal/FileCopyDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FileCopyDialog {
private readonly ProgressBar _progressTotal;
private readonly ProgressBar _progressCurrent;
private readonly Label _labelTotal;
private readonly Label _labelCurrent;
//private readonly Label _labelCurrent;
private long _copiedTotal = 0;
private long _sizeTotal = 0;

Expand All @@ -37,7 +37,7 @@ public FileCopyDialog(View parent, FSView from, FSView to) {
_cts.Cancel();
};

_dialog = new Dialog("Copy files", width / 2, 10, cancel);
_dialog = new Dialog("Copy files", width / 2, 7, cancel);

var lbl = new Label(" total: ") { X = 0, Y = 0 };
_dialog.Add(lbl);
Expand All @@ -50,21 +50,24 @@ public FileCopyDialog(View parent, FSView from, FSView to) {
};
_dialog.Add(_progressTotal);

_labelTotal = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
_dialog.Add(_labelTotal);
//_labelTotal = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
//_dialog.Add(_labelTotal);

lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(_labelTotal) };
lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(lbl) };
_dialog.Add(lbl);
_progressCurrent = new ProgressBar() {
X = Pos.Right(lbl),
Y = Pos.Bottom(_progressTotal),
Y = 1,
Width = Dim.Fill(),
Height = 1
};
_dialog.Add(_progressCurrent);

_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
_dialog.Add(_labelCurrent);
//_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
//_dialog.Add(_labelCurrent);

_labelTotal = new Label("?") { X = 0, Y = Pos.Bottom(lbl) };
_dialog.Add(_labelTotal);
}

public void Start() {
Expand Down Expand Up @@ -98,15 +101,21 @@ private async Task Copy(IFileStorage fsFrom, IFileStorage fsTo, IOPath pathFrom,
byte[] buffer = ArrayPool<byte>.Shared.Rent(DefaultCopyBufferSize);
try {
int bytesRead;
long totalRead = 0;
while((bytesRead = await streamFrom.ReadAsync(new Memory<byte>(buffer), _cts.Token)) != 0) {
await streamTo.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, bytesRead), _cts.Token);
float fraction = streamFrom.Position / (float)streamFrom.Length;

_copiedTotal += bytesRead;
totalRead += bytesRead;
float fracCurrent = totalRead / (float)streamFrom.Length;
float fracTotal = _copiedTotal / (float)_sizeTotal;
string status = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}";

Application.MainLoop.Invoke(() => {
_progressCurrent.Fraction = fraction;
_copiedTotal += bytesRead;
_labelCurrent.Text = $"{streamFrom.Position.Bytes()} / {streamFrom.Length.Bytes()}";
_labelTotal.Text = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}";

_progressCurrent.Fraction = fracCurrent;
_progressTotal.Fraction = fracTotal;
_labelTotal.Text = status;
});
}

Expand All @@ -127,14 +136,8 @@ private void RunCopy() {
IReadOnlyCollection<IOEntry> sourceEntries = await Explode(_from.Fs, _from.SelectedEntry!);
_sizeTotal = sourceEntries.Sum(e => e.Size!.Value);

int i = 0;
foreach(IOEntry entry in sourceEntries) {

await Copy(_from.Fs, _to.Fs, entry.Path, _to.CurrentPath.Combine(entry.Path.Name));

Application.MainLoop.Invoke(() => {
_progressTotal.Fraction = i++ * 100.0f / sourceEntries.Count;
});
}
} catch(Exception ex1) {
ex = ex1;
Expand All @@ -143,8 +146,10 @@ private void RunCopy() {
Application.MainLoop.Invoke(() => {
if(ex != null) {
MessageBox.ErrorQuery(60, 10, "Error", ex.ToString(), "Ok");
} else {
MessageBox.Query(60, 5, "Done", "Files copied.", "Ok");
Application.RequestStop();
}
Application.RequestStop();
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/Stowage.Terminal/TextFileEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public TextFileEditorWindow(IFileStorage fs, IOEntry entry) : base("Quick Edit",
_statusBar = new StatusBar(new StatusItem[] {
new StatusItem(Key.F2, "~F2~ Save", SaveContent),
_statusSize,
_statusCursorPos,
new StatusItem(Key.F10, "~F10~ Close", () => Application.RequestStop())
_statusCursorPos
});

Add(_textView);
Expand Down

0 comments on commit ad5c3cd

Please sign in to comment.