Skip to content

Commit ad5c3cd

Browse files
committed
terminal experiments
1 parent 7f69f52 commit ad5c3cd

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

src/Stowage.Terminal/AppTopLevel.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ class AppTopLevel : Toplevel {
1313

1414
public AppTopLevel(IFileStorage fs) {
1515
_fs = fs;
16-
ColorScheme = Colors.Base;
17-
18-
MenuBar = new MenuBar(new MenuBarItem[] {
19-
new MenuBarItem("_File", new MenuItem[] {
20-
new MenuItem("_Quit", "", () => Application.RequestStop()),
21-
}),
22-
new MenuBarItem("_Help", new MenuItem[] {
23-
new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")),
24-
}),
25-
});
26-
MenuBar.Visible = true;
16+
//ColorScheme = Colors.Base;
17+
18+
//MenuBar = new MenuBar(new MenuBarItem[] {
19+
// new MenuBarItem("_File", new MenuItem[] {
20+
// new MenuItem("_Quit", "", () => Application.RequestStop()),
21+
// }),
22+
// new MenuBarItem("_Help", new MenuItem[] {
23+
// new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")),
24+
// }),
25+
//});
26+
//MenuBar.Visible = true;
2727

2828
_fsView1 = new FSView(_fs) {
2929
X = 0,
30-
Y = 1,
30+
Y = 0,
3131
Width = Dim.Percent(50),
3232
Height = Dim.Fill() - 1
3333
};

src/Stowage.Terminal/FileCopyDialog.cs

+25-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FileCopyDialog {
2222
private readonly ProgressBar _progressTotal;
2323
private readonly ProgressBar _progressCurrent;
2424
private readonly Label _labelTotal;
25-
private readonly Label _labelCurrent;
25+
//private readonly Label _labelCurrent;
2626
private long _copiedTotal = 0;
2727
private long _sizeTotal = 0;
2828

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

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

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

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

56-
lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(_labelTotal) };
56+
lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(lbl) };
5757
_dialog.Add(lbl);
5858
_progressCurrent = new ProgressBar() {
5959
X = Pos.Right(lbl),
60-
Y = Pos.Bottom(_progressTotal),
60+
Y = 1,
6161
Width = Dim.Fill(),
6262
Height = 1
6363
};
6464
_dialog.Add(_progressCurrent);
6565

66-
_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
67-
_dialog.Add(_labelCurrent);
66+
//_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) };
67+
//_dialog.Add(_labelCurrent);
68+
69+
_labelTotal = new Label("?") { X = 0, Y = Pos.Bottom(lbl) };
70+
_dialog.Add(_labelTotal);
6871
}
6972

7073
public void Start() {
@@ -98,15 +101,21 @@ private async Task Copy(IFileStorage fsFrom, IFileStorage fsTo, IOPath pathFrom,
98101
byte[] buffer = ArrayPool<byte>.Shared.Rent(DefaultCopyBufferSize);
99102
try {
100103
int bytesRead;
104+
long totalRead = 0;
101105
while((bytesRead = await streamFrom.ReadAsync(new Memory<byte>(buffer), _cts.Token)) != 0) {
102106
await streamTo.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, bytesRead), _cts.Token);
103-
float fraction = streamFrom.Position / (float)streamFrom.Length;
107+
108+
_copiedTotal += bytesRead;
109+
totalRead += bytesRead;
110+
float fracCurrent = totalRead / (float)streamFrom.Length;
111+
float fracTotal = _copiedTotal / (float)_sizeTotal;
112+
string status = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}";
104113

105114
Application.MainLoop.Invoke(() => {
106-
_progressCurrent.Fraction = fraction;
107-
_copiedTotal += bytesRead;
108-
_labelCurrent.Text = $"{streamFrom.Position.Bytes()} / {streamFrom.Length.Bytes()}";
109-
_labelTotal.Text = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}";
115+
116+
_progressCurrent.Fraction = fracCurrent;
117+
_progressTotal.Fraction = fracTotal;
118+
_labelTotal.Text = status;
110119
});
111120
}
112121

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

130-
int i = 0;
131139
foreach(IOEntry entry in sourceEntries) {
132-
133140
await Copy(_from.Fs, _to.Fs, entry.Path, _to.CurrentPath.Combine(entry.Path.Name));
134-
135-
Application.MainLoop.Invoke(() => {
136-
_progressTotal.Fraction = i++ * 100.0f / sourceEntries.Count;
137-
});
138141
}
139142
} catch(Exception ex1) {
140143
ex = ex1;
@@ -143,8 +146,10 @@ private void RunCopy() {
143146
Application.MainLoop.Invoke(() => {
144147
if(ex != null) {
145148
MessageBox.ErrorQuery(60, 10, "Error", ex.ToString(), "Ok");
149+
} else {
150+
MessageBox.Query(60, 5, "Done", "Files copied.", "Ok");
151+
Application.RequestStop();
146152
}
147-
Application.RequestStop();
148153
});
149154
});
150155
}

src/Stowage.Terminal/TextFileEditorWindow.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public TextFileEditorWindow(IFileStorage fs, IOEntry entry) : base("Quick Edit",
4949
_statusBar = new StatusBar(new StatusItem[] {
5050
new StatusItem(Key.F2, "~F2~ Save", SaveContent),
5151
_statusSize,
52-
_statusCursorPos,
53-
new StatusItem(Key.F10, "~F10~ Close", () => Application.RequestStop())
52+
_statusCursorPos
5453
});
5554

5655
Add(_textView);

0 commit comments

Comments
 (0)