hexchat_unsafe_plugin/
infoid.rs

1// This file is part of Hexchat Plugin API Bindings for Rust
2// Copyright (C) 2018, 2021 Soni L.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17use std::borrow::Cow;
18
19/// A hexchat_get_info key.
20#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Copy, Clone)]
21pub enum InfoId<'a> {
22    /// Returns the away message, or `None` if the user is not away.
23    Away,
24    /// Returns the current channel name.
25    Channel,
26    /// Returns the current charset.
27    Charset,
28    /// Returns the hexchat configuration directory, e.g. `/home/user/.config/hexchat`.
29    Configdir,
30    /// Returns the text event format string for the given text event name.
31    EventText(&'a str),
32    /// Returns the (real) hostname of the current server.
33    Host,
34    /// Returns the contents of the input box.
35    Inputbox,
36    // TODO replace with a get_libdirfs function!
37    // /// Returns the library directory, e.g. `/usr/lib/hexchat`.
38    // ///
39    // /// May not always work, as this string isn't necessarily UTF-8, but local file system
40    // /// encoding.
41    // Libdirfs,
42    /// Returns the channel modes, if known, or `None`.
43    Modes,
44    /// Returns the current network name, or `None`.
45    Network,
46    /// Returns the user's current nick.
47    Nick,
48    /// Returns the user's nickserv password, if any, or `None`
49    Nickserv,
50    /// Returns the current server name, or `None` if you are not connected.
51    Server,
52    /// Returns the current channel topic.
53    Topic,
54    /// Returns the HexChat version string.
55    Version,
56    /// Returns the window status: "active", "hidden" or "normal".
57    WinStatus,
58}
59
60impl<'a> InfoId<'a> {
61    pub fn name(&self) -> Cow<'static, str> {
62        match *self {
63            InfoId::EventText(s) => {
64                let mut eventtext: String = "event_text ".into();
65                eventtext.push_str(&s);
66                eventtext.into()
67            },
68            InfoId::Away      => "away".into(),
69            InfoId::Channel   => "channel".into(),
70            InfoId::Charset   => "charset".into(),
71            InfoId::Configdir => "configdir".into(),
72            InfoId::Host      => "host".into(),
73            InfoId::Inputbox  => "inputbox".into(),
74            //InfoId::Libdirfs  => "libdirfs".into(),
75            InfoId::Modes     => "modes".into(),
76            InfoId::Network   => "network".into(),
77            InfoId::Nick      => "nick".into(),
78            InfoId::Nickserv  => "nickserv".into(),
79            InfoId::Server    => "server".into(),
80            InfoId::Topic     => "topic".into(),
81            InfoId::Version   => "version".into(),
82            InfoId::WinStatus => "win_status".into(),
83        }
84    }
85}