sukiboo commited on
Commit
c8203e2
·
1 Parent(s): d900c84

ui tweaks

Browse files
Files changed (3) hide show
  1. app.py +2 -2
  2. src/rendering.py +2 -9
  3. src/ui.py +92 -47
app.py CHANGED
@@ -1,6 +1,6 @@
1
- from src.ui import create_app
2
 
3
  app = create_app()
4
 
5
  if __name__ == "__main__":
6
- app.launch()
 
1
+ from src.ui import LAUNCH_KWARGS, create_app
2
 
3
  app = create_app()
4
 
5
  if __name__ == "__main__":
6
+ app.launch(**LAUNCH_KWARGS)
src/rendering.py CHANGED
@@ -8,13 +8,11 @@ PRE_STYLE: str = (
8
  "font-size:14px;line-height:1.5;color:#b0b0b0;background:transparent;"
9
  "padding:0;border:none;margin:0;white-space:pre;overflow-x:auto"
10
  )
11
- CURSOR: str = '<span style="animation:blink 1s step-end infinite">\u2588</span>'
12
- BLINK_CSS: str = "<style>@keyframes blink{50%{opacity:0}}</style>"
13
  PROGRESS_WIDTH: int = 40
14
 
15
 
16
  def _pre(text: str) -> str:
17
- return f'{BLINK_CSS}<pre style="{PRE_STYLE}">{text}</pre>'
18
 
19
 
20
  def render_html(languages: dict[str, int], url: str = "") -> str:
@@ -40,8 +38,6 @@ def render_html(languages: dict[str, int], url: str = "") -> str:
40
  lines.append(f" {'':20s} {'_' * BAR_WIDTH} {'_' * 10} {'_' * 6}")
41
  lines.append("")
42
  lines.append(f"{'Total':<20s} {'':>{BAR_WIDTH}s} {total:>10,} 100.0%")
43
- lines.append(f"&gt; {CURSOR}")
44
-
45
  return _pre("\n".join(lines))
46
 
47
 
@@ -49,7 +45,6 @@ def _error_html(message: str) -> str:
49
  lines = [
50
  "repo-stats \u2014 lines of code by language",
51
  f"error: {escape(message)}",
52
- f"{CURSOR}",
53
  ]
54
  return _pre("\n".join(lines))
55
 
@@ -62,7 +57,5 @@ def _progress_html(progress: ProgressInfo) -> str:
62
  filled = round(pct * PROGRESS_WIDTH)
63
  bar = "#" * filled + "." * (PROGRESS_WIDTH - filled)
64
  pct_str = f"{pct * 100:5.1f}%"
65
- text = (
66
- f"{progress.desc}\n[{bar}] {pct_str} {progress.completed}/{progress.total} files\n{CURSOR}"
67
- )
68
  return _pre(text)
 
8
  "font-size:14px;line-height:1.5;color:#b0b0b0;background:transparent;"
9
  "padding:0;border:none;margin:0;white-space:pre;overflow-x:auto"
10
  )
 
 
11
  PROGRESS_WIDTH: int = 40
12
 
13
 
14
  def _pre(text: str) -> str:
15
+ return f'<pre style="{PRE_STYLE}">{text}</pre>'
16
 
17
 
18
  def render_html(languages: dict[str, int], url: str = "") -> str:
 
38
  lines.append(f" {'':20s} {'_' * BAR_WIDTH} {'_' * 10} {'_' * 6}")
39
  lines.append("")
40
  lines.append(f"{'Total':<20s} {'':>{BAR_WIDTH}s} {total:>10,} 100.0%")
 
 
41
  return _pre("\n".join(lines))
42
 
43
 
 
45
  lines = [
46
  "repo-stats \u2014 lines of code by language",
47
  f"error: {escape(message)}",
 
48
  ]
49
  return _pre("\n".join(lines))
50
 
 
57
  filled = round(pct * PROGRESS_WIDTH)
58
  bar = "#" * filled + "." * (PROGRESS_WIDTH - filled)
59
  pct_str = f"{pct * 100:5.1f}%"
60
+ text = f"{progress.desc}\n[{bar}] {pct_str} {progress.completed}/{progress.total} files"
 
 
61
  return _pre(text)
src/ui.py CHANGED
@@ -46,54 +46,99 @@ def analyze_repo(url: str) -> Generator[str, None, None]:
46
  yield _error_html(f"Unexpected error: {e}")
47
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  def create_app() -> gr.Blocks:
50
- with gr.Blocks(
51
- theme=gr.themes.Monochrome(), # type: ignore[attr-defined]
52
- css="""
53
- * { border-radius: 0 !important; }
54
- .gradio-container {
55
- max-width: 960px !important;
56
- background: #111 !important;
57
- font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace !important;
58
- }
59
- .main, .contain, .wrap { background: transparent !important; }
60
- footer, header { display: none !important; }
61
-
62
- /* kill all gradio wrapper chrome on the input */
63
- #cli, #cli *, #cli div, #cli .wrap, #cli .container {
64
- background: transparent !important;
65
- border: none !important;
66
- box-shadow: none !important;
67
- outline: none !important;
68
- }
69
- #cli { position: relative; padding-left: 1.5em !important; }
70
- #cli .label-wrap { display: none !important; }
71
- #cli textarea, #cli input {
72
- font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace !important;
73
- font-size: 14px !important;
74
- background: transparent !important;
75
- color: #b0b0b0 !important;
76
- border: none !important;
77
- box-shadow: none !important;
78
- outline: none !important;
79
- padding: 8px 0 !important;
80
- caret-color: #b0b0b0;
81
- }
82
- #cli::before {
83
- content: '>';
84
- position: absolute;
85
- left: 0;
86
- top: 50%;
87
- transform: translateY(-50%);
88
- color: #b0b0b0;
89
- font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace;
90
- font-size: 14px;
91
- z-index: 1;
92
- pointer-events: none;
93
- }
94
- """,
95
- title="repo-stats",
96
- ) as app:
97
  url_input = gr.Textbox(
98
  show_label=False,
99
  placeholder="owner/repo",
 
46
  yield _error_html(f"Unexpected error: {e}")
47
 
48
 
49
+ _CSS = """
50
+ * { border-radius: 0 !important; }
51
+ .gradio-container {
52
+ max-width: 960px !important;
53
+ background: #111 !important;
54
+ font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace !important;
55
+ }
56
+ .main, .contain, .wrap { background: transparent !important; }
57
+ footer, header { display: none !important; }
58
+
59
+ /* kill all gradio wrapper chrome on the input */
60
+ #cli, #cli *, #cli div, #cli .wrap, #cli .container {
61
+ background: transparent !important;
62
+ border: none !important;
63
+ box-shadow: none !important;
64
+ outline: none !important;
65
+ }
66
+ #cli { position: relative; padding-left: 1.5em !important; }
67
+ #cli .label-wrap { display: none !important; }
68
+ #cli textarea, #cli input {
69
+ font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace !important;
70
+ font-size: 14px !important;
71
+ background: transparent !important;
72
+ color: #b0b0b0 !important;
73
+ border: none !important;
74
+ box-shadow: none !important;
75
+ outline: none !important;
76
+ padding: 8px 0 !important;
77
+ caret-color: #b0b0b0;
78
+ }
79
+ @keyframes blink { 50% { opacity: 0; } }
80
+ #cli::before {
81
+ content: '>';
82
+ position: absolute;
83
+ left: 0;
84
+ top: 50%;
85
+ transform: translateY(-50%);
86
+ color: #b0b0b0;
87
+ font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace;
88
+ font-size: 14px;
89
+ z-index: 1;
90
+ pointer-events: none;
91
+ }
92
+ #cli-cursor {
93
+ position: absolute;
94
+ left: 1.5em;
95
+ top: 50%;
96
+ transform: translateY(-50%);
97
+ color: #b0b0b0;
98
+ font-family: 'JetBrains Mono','Fira Code','SF Mono','Consolas',monospace;
99
+ font-size: 14px;
100
+ pointer-events: none;
101
+ z-index: 1;
102
+ animation: blink 1s step-end infinite;
103
+ }
104
+ """
105
+
106
+ _HEAD = """
107
+ <script>
108
+ (function init() {
109
+ const cli = document.getElementById('cli');
110
+ if (!cli) { setTimeout(init, 200); return; }
111
+ const input = cli.querySelector('textarea') || cli.querySelector('input');
112
+ if (!input) { setTimeout(init, 200); return; }
113
+ if (cli.querySelector('#cli-cursor')) return;
114
+ const cur = document.createElement('span');
115
+ cur.id = 'cli-cursor';
116
+ cur.textContent = '\u2588';
117
+ cli.appendChild(cur);
118
+ const measure = document.createElement('span');
119
+ measure.style.cssText = 'position:absolute;visibility:hidden;white-space:pre;' +
120
+ getComputedStyle(input).font;
121
+ cli.appendChild(measure);
122
+ const update = () => {
123
+ measure.textContent = input.value || '';
124
+ cur.style.left = (1.5 * 14 + measure.offsetWidth) + 'px';
125
+ };
126
+ input.addEventListener('input', update);
127
+ new MutationObserver(update).observe(input, {attributes: true, childList: true});
128
+ update();
129
+ })();
130
+ </script>
131
+ """
132
+
133
+ LAUNCH_KWARGS: dict = {
134
+ "theme": gr.themes.Monochrome(), # type: ignore[attr-defined]
135
+ "css": _CSS,
136
+ "head": _HEAD,
137
+ }
138
+
139
+
140
  def create_app() -> gr.Blocks:
141
+ with gr.Blocks(title="repo-stats") as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  url_input = gr.Textbox(
143
  show_label=False,
144
  placeholder="owner/repo",