Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decaffeinate lib/ui/progress #763

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions lib/ui/progress.coffee

This file was deleted.

77 changes: 77 additions & 0 deletions lib/ui/progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use babel'
import { CompositeDisposable } from 'atom';
import client from '../connection/client';
import { formatTimePeriod } from '../misc';

export let progs = {}

let subs;
let ink;
export function activate(ink_in) {
subs = new CompositeDisposable;
ink = ink_in;
client.handle({'progress': (t, id, m) => this[t](id, m)});
let status = [];
subs.add(
client.onWorking(() => {
return status = ink.progress.add(null, {description: 'Julia'});
}),
client.onDone(() => (status != null ? status.destroy() : undefined)), // status?.destroy()
client.onAttached(() => ink.progress.show()),
client.onDetached(() => clear())
);
}

export function deactivate() {
clear();
subs.dispose();
}

export function add(id) {
const pr = ink.progress.add();
pr.t0 = Date.now();
pr.showTime = true;
progs[id] = pr;
}

export function progress(id, prog) {
const pr = progs[id];
if (pr == null) { return; }
pr.level = prog;
if (pr.showTime) { return rightText(id, null); }
}

export function message(id, m) { return (progs[id] != null ? progs[id].message = m : undefined); } // progs[id]?.message = m

export function leftText(id, m) { return (progs[id] != null ? progs[id].description = m : undefined); } // progs[id]?.description = m

export function rightText(id, m) {
const pr = progs[id];
if (pr == null) { return; }
if (m != null ? m.length : undefined) {
pr.rightText = m;
return pr.showTime = false;
} else {
const dt = ((Date.now() - pr.t0)*((1/pr.level) - 1))/1000;
pr.showTime = true;
return pr.rightText = formatTimePeriod(dt);
}
}

export function deleteit(id) {
const pr = progs[id];
if (pr == null) { return; }
pr.destroy();
delete progs[id];
}

export function clear() {
for (let _ in progs) {
const p = progs[_];
if (p != null) {
p.destroy();
}
}
progs = {};
ink.progress.hide();
}