Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example.pl] add example.pl #640

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions scripts/example.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use strict;
use vars qw($VERSION %IRSSI);

use Irssi;

$VERSION = '0.01';
%IRSSI = (
authors => 'noname',
contact => '[email protected]',
name => 'example',
description => 'This script really does nothing. Sorry.',
license => 'Public Domain',
url => 'https://scripts.irssi.org/',
changed => '2019-06-07',
modules => '',
commands=> 'example',
);

my $help = << "END";
%9Name%9
$IRSSI{name}
%9Version%9
$VERSION
%9description%9
$IRSSI{description}
%9See also%9
null.pl
https://perldoc.perl.org/perl.html
https://github.com/irssi/irssi/blob/master/docs/perl.txt
https://github.com/irssi/irssi/blob/master/docs/signals.txt
https://github.com/irssi/irssi/blob/master/docs/formats.txt
END

my $test_str;

sub cmd {
my ($args, $server, $witem)=@_;
if (defined $witem) {
$witem->printformat(MSGLEVEL_CLIENTCRAP, 'example_theme',
$test_str, $test_str, $test_str);
} else {
Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'example_theme',
$test_str, $test_str, $test_str);
}
}

sub cmd_help {
my ($args, $server, $witem)=@_;
$args=~ s/\s+//g;
if ($IRSSI{name} eq $args) {
Irssi::print($help, MSGLEVEL_CLIENTCRAP);
Irssi::signal_stop();
}
}

sub sig_setup_changed {
$test_str= Irssi::settings_get_str($IRSSI{name}.'_test_str');
}

Irssi::theme_register([
'example_theme', '{hilight $0} $1 {error $2}',
]);

Irssi::signal_add('setup changed', \&sig_setup_changed);

Irssi::settings_add_str($IRSSI{name} ,$IRSSI{name}.'_test_str', 'hello world!');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the 'hello world!' be $test_str instead, and the default set by initialising this variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings_add_str let add irssi a setting with default value 'hello world!'

`sub sig_setup_changed' read out settings and maybe check values or react on chance of value

$test_str is for working in script (value is checked and change is already done)
init of this scalar is on last line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, makes sense. I never stop learning, and I think I got it now. So please disregard my comment.


Irssi::command_bind($IRSSI{name}, \&cmd);
Irssi::command_bind('help', \&cmd_help);

sig_setup_changed();