-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathripgrep.html
98 lines (88 loc) · 3.2 KB
/
ripgrep.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{% extends "base.html" %}
{% block title %}ripgrep{% if pattern %}: {{ pattern }}{% endif %}{% endblock %}
{% block extra_head %}
<style>
pre {
padding-left: {{ widest_line_number + 1.5 }}ch;
white-space: pre-wrap;
}
pre a.line-number:link {
-webkit-user-select: none;
display: inline-block;
width: {{ widest_line_number + 1.5 }}ch;
margin-left: -{{ widest_line_number + 1.5 }}ch;
text-decoration: none;
color: #666;
}
form.ripgrep label {
font-weight: normal;
display: inline;
}
pre.match {
background-color: #FFFF99;
}
.glob-examples {
font-size: 0.85em;
}
.glob-examples code {
background-color: #eee;
padding: 0 2px;
border: 1px solid #ccc;
}
</style>
{% endblock %}
{% block content %}
<h1>ripgrep</h1>
<form class="ripgrep" action="{{ urls.path("/-/ripgrep") }}" method="get">
<p>
<input type="search" name="pattern" value="{{ pattern }}">
<input type="submit" value="Search">
</p>
<p><strong>Options:</strong> <label><input type="checkbox" name="literal"{% if literal %} checked={% endif %}> Literal search (not regex)</label> <label><input type="checkbox" name="ignore"{% if ignore %} checked={% endif %}> Ignore case</label></p>
<p>
<label><strong>File pattern</strong>: <input type="text" style="max-width: 20em" name="glob" value="{{ globs.0 }}"></label>
</p>
<p class="glob-examples">For example <code>*.py</code> or <code>**/templates/**/*.html</code> or <code>datasette/**</code> or </code><code>!setup.py</code>
</p>
{% if globs|length > 1 %}
<p><strong>Additional patterns</strong></p>
{% for glob in globs[1:] %}
<p>
<input type="text" style="max-width: 20em" name="glob" value="{{ glob }}">
</p>
{% endfor %}
{% endif %}
</form>
{% if time_limit_hit %}<p>Time limit exceeded.</p>{% endif %}
{% set ns = namespace(ended=true) %}
{% for result in results %}
{% if result.type == "begin" %}
<h3>{{ fix_path(result.data.path.text) }}</h3>
<div style="overflow-x: auto">{% set ns.ended = false %}
{% endif %}
{% if result.type in ("match", "context") %}
<pre{% if result.type == "match" %} class="match"{% endif %}><a class="line-number" href="{{ urls.path("/-/ripgrep/view/" + url_quote(fix_path(result.data.path.text))) }}#L{{ result.data.line_number }}">{{ "%-4s" | format(result.data.line_number) }}</a><span>{{ result.data.lines.text }}</span></pre>
{% endif %}
{% if result.type == "end" %}{% set ns.ended = true %} </div>{% endif %}
{% endfor %}
{% if not ns.ended %} </div>{% endif %}
<script>
// Truncate really long lines
Array.from(document.querySelectorAll('pre span')).forEach(span => {
const content = span.innerText;
if (content.length > 400) {
span.textContent = content.slice(0, 400);
let original = content;
const a = document.createElement('a');
a.innerText = '[...]';
a.style.fontWeight = 'bold';
a.href = span.parentNode.querySelector('a').href;
span.appendChild(a);
a.addEventListener('click', e => {
e.preventDefault();
span.innerText = original;
})
}
});
</script>
{% endblock %}