v0.7.0 31c7fae

compiler.go RawHistoryFolder

1package filtering
2
3import (
4	"bufio"
5	"context"
6	"fmt"
7	"strings"
8	"time"
9
10	"github.com/bnema/dumber/internal/filtering/converter"
11	"github.com/bnema/dumber/internal/logging"
12)
13
14// DefaultFilterCompiler implements FilterCompiler using the converter package
15type DefaultFilterCompiler struct {
16	converter *converter.FilterConverter
17}
18
19// NewDefaultFilterCompiler creates a new default filter compiler
20func NewDefaultFilterCompiler() *DefaultFilterCompiler {
21	return &DefaultFilterCompiler{
22		converter: converter.NewFilterConverter(),
23	}
24}
25
26// CompileFromSources downloads and compiles filters from multiple URLs
27func (dfc *DefaultFilterCompiler) CompileFromSources(ctx context.Context, sources []string) (*CompiledFilters, error) {
28	compiled := NewCompiledFilters()
29
30	for _, url := range sources {
31		select {
32		case <-ctx.Done():
33			return nil, ctx.Err()
34		default:
35		}
36
37		filters, err := dfc.downloadAndCompile(ctx, url)
38		if err != nil {
39			logging.Error(fmt.Sprintf("Failed to compile from %s: %v", url, err))
40			continue
41		}
42
43		compiled.Merge(filters)
44	}
45
46	compiled.Version = fmt.Sprintf("compiled-%d", time.Now().Unix())
47	compiled.CompiledAt = time.Now()
48
49	return compiled, nil
50}
51
52// CompileFromData compiles filters from raw data bytes
53func (dfc *DefaultFilterCompiler) CompileFromData(data []byte) (*CompiledFilters, error) {
54	compiled := NewCompiledFilters()
55
56	// Reset converter for new compilation
57	dfc.converter = converter.NewFilterConverter()
58
59	// Parse line by line
60	scanner := bufio.NewScanner(strings.NewReader(string(data)))
61	lineCount := 0
62
63	for scanner.Scan() {
64		line := scanner.Text()
65		lineCount++
66
67		// Convert each line
68		if err := dfc.converter.ConvertEasyListLine(line); err != nil {
69			logging.Debug(fmt.Sprintf("Failed to convert filter line: %s, error: %v", line, err))
70			continue
71		}
72	}
73
74	if err := scanner.Err(); err != nil {
75		return nil, fmt.Errorf("error reading filter data: %w", err)
76	}
77
78	// Get compiled rules from converter
79	compiled.NetworkRules = dfc.converter.GetNetworkRules()
80	compiled.CosmeticRules = dfc.converter.GetCosmeticRules()
81	compiled.GenericHiding = dfc.converter.GetGenericHiding()
82	compiled.CompiledAt = time.Now()
83	compiled.Version = fmt.Sprintf("data-compile-%d", time.Now().Unix())
84
85	logging.Info(fmt.Sprintf("Compiled %d filter lines into %d network rules and %d cosmetic rules",
86		lineCount, len(compiled.NetworkRules), len(compiled.CosmeticRules)))
87
88	return compiled, nil
89}
90
91// downloadAndCompile downloads and compiles a single filter list
92func (dfc *DefaultFilterCompiler) downloadAndCompile(ctx context.Context, url string) (*CompiledFilters, error) {
93	// This would implement HTTP download - for now, return empty filters
94	logging.Debug(fmt.Sprintf("Would download and compile from %s", url))
95
96	compiled := NewCompiledFilters()
97	compiled.Version = fmt.Sprintf("stub-%d", time.Now().Unix())
98	compiled.CompiledAt = time.Now()
99
100	return compiled, nil
101}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close