Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Commit

Permalink
Add label describing current operation to progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
p-e-w committed May 18, 2013
1 parent 59f05e9 commit 01ca2dd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
14 changes: 8 additions & 6 deletions data/Startup/bash_startup
Expand Up @@ -40,15 +40,15 @@ function get_current_trap_command() {
}

# Sequence marking the start of the command prompt
FTCS_PROMPT_START=$(final_term_control_sequence 'A')
FTCS_PROMPT_START="$(final_term_control_sequence 'A')"

# Sequence marking the start of the command
# read from the command prompt
FTCS_COMMAND_START=$(final_term_control_sequence 'B')
FTCS_COMMAND_START="$(final_term_control_sequence 'B')"

# Sequence marking the end of the command
# read from the command prompt
FTCS_COMMAND_END=$(final_term_control_sequence 'C')
FTCS_COMMAND_END="$(final_term_control_sequence 'C')"

# Note that it is safe to prepend a new command to the current one
# but not to append it, because bash does not allow a semicolon
Expand All @@ -65,17 +65,19 @@ trap "if [ -t 1 ]; then send_control_sequence \"$FTCS_COMMAND_END\"; fi; $(get_c
# Termlet-related logic

function text_menu_start() {
echo $(final_term_control_sequence 'D' "$1")
# NOTE: Nested double quotes look strange, but are both valid and necessary;
# see http://stackoverflow.com/questions/4031007
echo "$(final_term_control_sequence 'D' "$1")"
}
export -f text_menu_start

function text_menu_end() {
echo $(final_term_control_sequence 'E' "$1")
echo "$(final_term_control_sequence 'E' "$1")"
}
export -f text_menu_end

function send_progress() {
send_control_sequence $(final_term_control_sequence 'F' "$1")
send_control_sequence "$(final_term_control_sequence 'F' "$1" "$2")"
}
export -f send_progress

Expand Down
4 changes: 2 additions & 2 deletions data/Termlets/wget
Expand Up @@ -15,14 +15,14 @@ while IFS= read -r line; do
while IFS= read -r -d $'\r' line; do
# Extract current progress percentage
if [[ $line =~ ^\ ?([0-9]{1,3})% ]]; then
send_progress "${BASH_REMATCH[1]}"
send_progress "${BASH_REMATCH[1]}" "Downloading $1..."
fi

echo -ne "\r$line"
done

# Process completed
send_progress "-1"
send_progress "-1" ""

# Print remaining output
echo -ne "\r$line"
Expand Down
14 changes: 11 additions & 3 deletions data/Themes/default/style.css
Expand Up @@ -87,9 +87,17 @@ MxScrollBar MxButton.vhandle:active {
border-image: none;
}

MxLabel.status-label {
padding: 2 10 4 5;
color: #777777;
MxLabel.progress-label {
padding: 2 5 4 5;
color: #ffffff;
/* TODO: This should work according to https://github.com/clutter-project/mx/commit/c108215, but doesn't */
/*text-shadow: 2 2 2 #000000;*/
}

/* This is the workaround */
MxLabel.progress-label-shadow {
padding: 3 4 3 6;
color: #000000;
}

MxProgressBar {
Expand Down
4 changes: 2 additions & 2 deletions src/Terminal.vala
Expand Up @@ -126,13 +126,13 @@ public class Terminal : Object, Themable {
title_updated(new_title);
}

private void on_output_progress_updated(int percentage) {
private void on_output_progress_updated(int percentage, string operation) {
#if HAS_UNITY
FinalTerm.launcher.progress_visible = true;
FinalTerm.launcher.progress = percentage / 100.0;
#endif

terminal_view.show_progress("Progress", percentage);
terminal_view.show_progress(percentage, operation);
}

private void on_output_progress_finished() {
Expand Down
5 changes: 3 additions & 2 deletions src/TerminalOutput.vala
Expand Up @@ -283,7 +283,8 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {
if (percentage == -1) {
progress_finished();
} else {
progress_updated(percentage);
var operation = stream_element.get_text_parameter(1, "");
progress_updated(percentage, operation);
}
break;

Expand Down Expand Up @@ -483,7 +484,7 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {

public signal void title_updated(string new_title);

public signal void progress_updated(int percentage);
public signal void progress_updated(int percentage, string operation);

public signal void progress_finished();

Expand Down
29 changes: 17 additions & 12 deletions src/TerminalView.vala
Expand Up @@ -30,9 +30,10 @@ public class TerminalView : Mx.BoxLayout, Themable {

public TerminalOutputView terminal_output_view;

private Mx.BoxLayout status_container;
private Mx.Label status_label;
private Clutter.Actor status_container;
private Mx.ProgressBar progress_bar;
private Mx.Label progress_label;
private Mx.Label progress_label_shadow;

public TerminalView(Terminal terminal, GtkClutter.Embed clutter_embed) {
this.terminal = terminal;
Expand Down Expand Up @@ -75,16 +76,18 @@ public class TerminalView : Mx.BoxLayout, Themable {
terminal_output_view.add_constraint(new Clutter.BindConstraint(container, Clutter.BindCoordinate.HEIGHT, 45));
container.clip_to_allocation = true;

status_container = new Mx.BoxLayout();
status_container.orientation = Mx.Orientation.HORIZONTAL;

status_label = new Mx.Label();
status_label.style_class = "status-label";
status_container.add(status_label);
status_container = new Clutter.Actor();

progress_bar = new Mx.ProgressBar();
status_container.add(progress_bar);
status_container.child_set_expand(progress_bar, true);
progress_bar.add_constraint(new Clutter.BindConstraint(status_container, Clutter.BindCoordinate.SIZE, 0));

progress_label_shadow = new Mx.Label();
progress_label_shadow.style_class = "progress-label-shadow";
status_container.add(progress_label_shadow);
progress_label = new Mx.Label();
progress_label.style_class = "progress-label";
status_container.add(progress_label);

add(status_container);

Expand All @@ -93,10 +96,11 @@ public class TerminalView : Mx.BoxLayout, Themable {
FinalTerm.register_themable(this);
}

public void show_progress(string caption, int percentage) {
public void show_progress(int percentage, string label = "") {
status_container.visible = true;
progress_bar.visible = true;
status_label.text = caption;
progress_label.text = label;
progress_label_shadow.text = label;
progress_bar.progress = (double)percentage / 100.0;
}

Expand All @@ -109,8 +113,9 @@ public class TerminalView : Mx.BoxLayout, Themable {
gutter.color = theme.gutter_color;
gutter.border_color = theme.gutter_border_color;

status_label.style = theme.style;
progress_bar.style = theme.style;
progress_label.style = theme.style;
progress_label_shadow.style = theme.style;
}

public bool window_has_focus() {
Expand Down

0 comments on commit 01ca2dd

Please sign in to comment.