summaryrefslogtreecommitdiff
path: root/src/canvas.cpp
blob: 08fd0a350867dd5a64d4de7b072cb290ae350efe (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
// Display images inside a terminal
// Copyright (C) 2023  JustKidding
//
// 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 "canvas/chafa.hpp"
#include "canvas/iterm2/iterm2.hpp"
#include "canvas/kitty/kitty.hpp"
#include "canvas/sixel.hpp"
#include "canvas/stdout.hpp"
#ifdef ENABLE_X11
#  include "canvas/x11/x11.hpp"
#endif
#ifdef ENABLE_WAYLAND
#  include "canvas/wayland/wayland.hpp"
#endif
#include "flags.hpp"
#include <fmt/format.h>

auto Canvas::create() -> std::unique_ptr<Canvas>
{
    const auto flags = Flags::instance();
    const auto logger = spdlog::get("main");

#ifdef ENABLE_WAYLAND
    if (flags->output == "wayland") {
        return std::make_unique<WaylandCanvas>();
    }
#else
    logger->debug("Wayland support not compiled in the binary");
#endif
#ifdef ENABLE_X11
    if (flags->output == "x11") {
        return std::make_unique<X11Canvas>();
    }
#else
    logger->debug("X11 support not compiled in the binary");
#endif

    if (flags->output == "kitty") {
        return std::make_unique<StdoutCanvas<Kitty>>(flags->output);
    }
    if (flags->output == "iterm2") {
        return std::make_unique<StdoutCanvas<Iterm2>>(flags->output);
    }
    if (flags->output == "sixel") {
        return std::make_unique<StdoutCanvas<Sixel>>(flags->output);
    }
    if (flags->output == "chafa") {
        return std::make_unique<StdoutCanvas<Chafa>>(flags->output);
    }
    throw std::runtime_error(fmt::format("output backend not supported (backend is {})", flags->output));
}