blob: 10378338f51e8a3f6c4fcc40417d9193447a5e0e (
plain)
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
|
/*
* Ricochet - A minimalist CLI web browser for fast, distraction-free navigation.
* Copyright (C) 2026 Richard Qin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <span>
#include <string_view>
#include <vector>
#include "ricochet/core/browser.hh"
#include "ricochet/core/license.hh"
namespace {
void print_usage( std::string_view program_name )
{
std::cout << "Usage: " << program_name << " [URL]\n"
<< "Example: " << program_name << " https://wikipedia.org\n";
}
} // namespace
int main( int argc, char* argv[] )
{
const std::span<char*> args_view( argv, static_cast<size_t>( argc ) );
const std::vector<std::string_view> args( args_view.begin(), args_view.end() );
ricochet::core::print_license_notice();
if ( args.size() < 2 ) {
std::cerr << "Error: No URL provided.\n";
print_usage( args[0] );
return 1;
}
const std::string_view input = args[1];
if ( input == "show" ) {
if ( args[2] == "w" ) {
ricochet::core::show_warranty();
} else if ( args[2] == "c" ) {
ricochet::core::show_copying();
} else {
std::cerr << "Error: Invalid argument for show command.\n";
print_usage( args[0] );
return 1;
}
return 0;
}
std::string start_url( input );
if ( !start_url.starts_with( "http://" ) && !start_url.starts_with( "https://" ) ) {
start_url.insert( 0, "https://" );
}
try {
return ricochet::core::Browser::run( start_url );
} catch ( const std::exception& e ) {
std::cerr << "Critical Error: " << e.what() << "\n";
return 1;
}
}
|